Take this example:
abstract class Base {
function __construct() {
echo 'Base __construct<br/>';
}
}
class Child extends Base {
function __construct() {
echo 'Child __construct<br/>';
}
}
$c = new Child();
Coming from a C# background, I expect the output to be
Base __construct
Child __construct
However, the actual output is just
Child __construct
No, the constructor of the parent class is not called if the child class defines a constructor.
From the constructor of your child class, you have to call the constructor of the parent’s class :
Passing it parameters, if needed.
Generally, you’ll do so at the beginning of the constructor of the child class, before any specific code ; which means, in your case, you’d have :
And, for reference, you can take a look at this page of the PHP manual : Constructors and Destructors — it states (quoting) :