Php – Can a subclass inherit also the constructor of the parent class, or must every class have its own constructor

oopPHP

Lets say I have an abstract ParentClass and a ChildClass. ChildClass extends ParentClass. Now ParentClass has got this nice constructor:

function __construct($tplFile) {
    $this->$tplFile = $tplFile;
}

Will ChildClass automatically inherit this one? And if I don't add any constructor to ChildClass, will I be able to say $foo = new ChildClass("foo.tpl.php"); so that the constructor of ParentClass gets called?

Best Answer

ChildClass will automatically inherit the constructor.

Related Topic