tags:

views:

66

answers:

3

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?

+3  A: 

ChildClass will automatically inherit thbe constructor.

Pekka
A: 

The answer to both questions is yes.

Anti Veeranna
+1  A: 

From the PHP manual:

Note:  Parent constructors are not called implicitly if the child class defines a
constructor. In order to run a parent constructor, a call to parent::__construct() 
within the child constructor is required.  
Don
Thanks - this answer was helpful to me.
Nathan Long