PHP Constructor and Destructor

Ads

In this current tutorial we will study about constructor and destructor of OOP.Like other OOP based languages PHP also supports constructor method for classes. As any other language's constructor method, in PHP constructor method is called for every object creation.

PHP Constructor & Destructor:

Like other OOP based languages PHP also supports constructor method for classes. As any other language's constructor method, in PHP constructor method is called for every object creation.

We can call parent's constructor method using parent::__construct() from the child constructor.

PHP also supports destructor like C++. This method is called as soon as the references of the object are removed or if we destroy the object .
This feature has been included in PHP 5. Like constructor method we can call the destructor method of parent class by parent::__destruct().

The destructor is being called any how, means even after executing the exit() code destructor method could be called.