PHP Syntax OOP Classes Components Methods Predefined Constructor


- Info:

- Parent constructors are not called implicitly, instead explicit call to parent::__construct() is needed.

- This tutorial is based on


- Example:

- Creat PHP Console Application Test.php.




class BaseClass {

function __construct() {

print "In BaseClass constructor\n";



$obj = new BaseClass();



- Old syntax:

- Before PHP 5 constructor functions were having the name equal to class name.

- If namespace is not defined and PHP 5 cannot find a __construct() it will search for function with the class name.