On Tue, 2002-06-11 at 23:21, William_dw -- Sqlcoders wrote: > Hi there!, > I'm trying to emulate a class destructor, according to the PHP documentation > I can emulate this by using a call to register_shutdown_function(), > containing the function to be called upon shutdown. > > While this apparently works outside a class, I want to use it inside a > class, in other words I want to have something like this: > > class cRoute{ > function cRoute(){ > //register the shutdown function in case people who use this class > dont call the appropiate close methods. > register_shutdown_function("cleanup()"); > } > > function cleanup(){ > //cleanup. > trigger_error("Please call close() before the page ends, to prevent > problems close() has been called automatically for you."); > $this->close(); > } > > function close(){ > //close open sockets, etc. > } > } > > I have tried: > register_shutdown_function("cleanup()"); > register_shutdown_function("$this->cleanup()"); > register_shutdown_function($this->cleanup()); > register_shutdown_function("cDB::cleanup()"); > > They all return something like: Warning: Unable to call ()() - function does > not exist in Unknown on line 0
>From the manual page for register_shutdown_function(): http://www.php.net/register_shutdown_function Note: Instead of a function name, an array containing an object reference and a method name can also be supplied. A simple test script: <?php error_reporting(E_ALL); class foo { function foo() { echo "Constructing foo.\n"; } function _foo() { echo "Destroying foo.\n"; } } $foo = new foo(); register_shutdown_function(array($foo, '_foo')); ?> Hope this helps, Torben > If anyone has any ideas I'd appreciate the help. > Thanks in advance!, > Dw. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Torben Wilson <[EMAIL PROTECTED]> http://www.thebuttlesschaps.com http://www.hybrid17.com http://www.inflatableeye.com +1.604.709.0506 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php