PHP is looking for the topmost (closest to the class instance) method __constructthat it can find. Then he performs only one.
Class A {
public function __construct() {
echo "From A";
}
}
Class B extends A {
public function __construct() {
echo "From B";
}
}
Class C extends A {}
Class D extends B {}
Class E extends B {
public function __construct() {
echo "from E";
}
}
new A();
new B();
new C();
new D();
new E();
And it parentturns to the next list up until it is no longer there (at what point it will generate an error) ...
So, in the class Estart parent::__construct()will execute the class constructor B.
In the class Bstart parent::__construct()will execute the class constructor A.
A parent::__construct() , ...