PHP Syntax OOP Terms Inheritance Call Parent Constructor

 

- Info:

- This tutorial shows how to call parent constructor.

 

- Example:

- Creat PHP Console Application Test.php.

 

Test.php

<?php

class BaseClass {

function __construct() {

print "In BaseClass constructor\n";

}

}

class SubClass extends BaseClass {

function __construct() {

parent::__construct();

print "In SubClass constructor\n";

}

}

$obj = new BaseClass();

$obj = new SubClass();

?>