PHP Syntax OOP Classes Components Methods Predefined Destructor

 

- Info:

- Destructor is method which is called as soon as there are no other references to a particular object, or during shutdown.

- Destructor is named sa __destruct().

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

- This tutorial is based on http://php.net/manual/en/language.oop5.decon.php.

 

- Example:

- Creat PHP Console Application Test.php.

 

Test.php

<?php

class MyDestructableClass {

 

function __construct() {

print "In constructor\n";

$this->name = "MyDestructableClass";

}

function __destruct() {

print "Destroying " . $this->name . "\n";

}

 

}

$obj = new MyDestructableClass();

?>