Multiple inheritance is not supported in PHP, what can we do if we implement code reuse to methods that use multiple classes? That's the combination. In a class, set another class as a property.
The following example simulates multiple inheritance.
View SOURCEPRINT?01
Class User {
The private $name = "Tom";
The Public Function getname () {
return $this->name;
06}
07}
Class teacher{
The private $lengthofservice = 5; Seniority
Ten public Function Getlengthofservice () {
One return $this->lengthofservice;
12}
13}
The set method in the class 14//above is not written.
15//If there is a graduate student, it is also a seniority.
Class Graduatestudent extends User {
Private $teacher;
The Public Function __construct () {
$this->teacher = new Teacher ();
20}
Public Function Getlengthofservice () {
return $this->teacher->getlengthofservice ();
23}
24}
$graduatestudent = new Graduatestudent ();
The echo "name is". $graduatestudent->getname (). " <br> ";
echo "Lengthofservice is". $graduatestudent->getlengthofservice ();
28
?>