Last time i had written blog on `Constructor`. But left the `Destructor` part. So today in this blog we will figure out the destructor. The destructor method is called as soon as all the references to a particular object are removed or when the object is explicitly destroyed or in any order in shutdown sequence. This makes destructor suitable for any final action we want to perform after the release of an object. Like to free up resources once we have done with them.
In PHP 5 and successive versions we describe Destructor as :
function _destruct() {
}
Like constructors parent destructor will not be called implicitly by the engine. In order to run parent destructor, we have to explicitly call as parent::_destruct(); in the destructor body.
Destructors called during the script shutdown have HTTP headers already sent. Attempting to throw an exception from a destructor which called in the time of script termination causes fatal error.