Destructor in PHP

In this article I explain about how to use destructor in PHP.
  • 1900

Destructor

The destructor is another feature of "OOP". The destructor concept was introduced in PHP5 and it is conceptually similar to that of other object oriented languages. The destructor method will be called as soon as there are no other references to a particular object or when the object has been explicitly destroyed.

Example

<?
php
class
MyClass
{

function __construct()
{

print "In constructor";

$this->name = "MyClass obj explicity";

}

 

function __destruct()
{

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

}

}

 

$obj = new Myclass();

?>

Output

destructor-in-php.jpg

© 2020 DotNetHeaven. All rights reserved.