trait
is kind of solution to the famous
multiple inheritance
problem in PHP. Using traits we can access methods from different traits that we use in our class
class Mobile {
    public function battery() {
        echo 'Battery: MB_06, MF_02, MF_00' . PHP_EOL;
    }
}
trait Laser {
    public function power() {
        echo 'Power: 10 mW' . PHP_EOL;
    }
}
trait Projector {
    public function range() {
        echo 'Range: 2 M' . PHP_EOL;
    }
}
class Galaxy extends Mobile {
    use Laser;
    use Projector;
}

$obj1 = new Galaxy;

$obj1->range();
$obj1->power();
$obj1->battery();
by Valeri Tandilashvili
4 years ago
PHP
OOP
PHP official doc
2
Pro tip: use ```triple backticks around text``` to write in code fences