Php Destructor

What is Php Destructor?

destructors – a function to be called when an object is deleted. PHP 5 introduces a destructor concept similar to that of other object-oriented languages, such as C++.
PHP calls destructors as soon as objects are no longer available, and the destructor function, __destruct(), takes no parameters.
void __destruct ( void )

why use destructor?
It gives the object an opportunity to prepare to be killed. This could mean manual cleanup, state persistence, etc.

you have create database object to communicate with database server after communicate with database server then you want to free database object through __destruct () method.

function __construct()
  $this->link = mysql_connect($this->server.':'.$this->port, $this->username);
    die('Could not connect: '.mysql_error());

  if(!mysql_select_db($this->database, $this->link))
    die('Could not select database: '.mysql_error());

function __destruct()
    $this->link = null;