Answer: Inside the child class constructor, call parent::__construct().
class ParentClass {
public function __construct($value) {
echo "Parent got $value\n";
}
}
class ChildClass extends ParentClass {
public function __construct($value) {
parent::__construct($value); // call parent constructor
echo "Child constructor\n";
}
}
new ChildClass(5);
Output: Parent got 5 then Child constructor.
In PHP, if a child class defines its own __construct(), the parent's constructor is not called automatically, so you must call it yourself with the keyword parent (lower case) and the scope operator ::. If the child has no constructor, the parent's constructor is inherited and runs automatically.