OOPS in PHP 5 – __destruct() Method

Destructor are special function in Object Oriented Programming. It gets called automatically whenever object of a class is destroyed or goes out of scope. This is useful for clean up operation before cleaning the memory. PHP5 uses special keyword “__destruct” to define destructor of the class.

Example on Destructor Class in PHP 5:

<?
class Master
{
    function __destruct()
    {
        echo "Destructor Called";
    }
}
$a = new Master();
?>

So when the page operation is completed destructor function is called automatically.

Share This Post

Related Articles

Leave a Reply

*