<?
/*
How to setup a simple destructor to call a method of an object
when the script is terminated - (without using PEAR). 
Scott Hurring <scott at hurring dot com>

This code only applies to PHP versions less than 5,
since in PHP5, actual constructors and destructors
are fully supported by the object model.
*/

class TestClass {

    function 
TestClass() {
        
register_shutdown_function('TestClass_Destructor'$this);
    }
    function 
_TestClass() {
        print 
"Destruction!\n";
    }

// End of class


// Note: This function is NOT in the TestClass
function TestClass_Destructor($obj) {
    
$obj->_TestClass();
}

// Explicit construction
$test = new TestClass();

// Implicit destruction will occur now, at program termination
exit;

?>