note 28973 modified in function.register-shutdown-function by tix
| From: | tix@php.net | Date: | Wed, 29 Jan 2003 14:30:05 +0000 |
| Subject: | note 28973 modified in function.register-shutdown-function by tix | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-43074@lists.php.net to get a copy of this message | ||
One more note to add about register_shutdown_function and objects.
It is possible to self-register the object from the constructor, but even using the syntax:
register_shutdown_function(array(&$this,'shutdown'))
will only result in the function being called with the object in the "just initialized"
state, any changes made to the object after construction will not be there when the script actually
exits.
But if you use:
$obj = new object();
register_shutdown_function(array(&$obj,'shutdown'));
the object method 'shutdown' will be called with the current state of the object intact.
[Editor's note: The explaination for this behaviour is really simple.
"$obj = new object()" creates a copy of the object which you can refer with $this in the
object's constructor.
To solve this "problem" you should use "$obj = &new object()" which assign
the reference to the current object.]
--was--
One more note to add about register_shutdown_function and objects.
It is possible to self-register the object from the constructor, but even using the syntax:
register_shutdown_function(array(&$this,'shutdown'))
will only result in the function being called with the object in the "just initialized"
state, any changes made to the object after construction will not be there when the script actually
exits.
But if you use:
$obj = new object();
register_shutdown_function(array(&$obj,'shutdown'));
the object method 'shutdown' will be called with the current state of the object intact.
http://www.php.net/manual/en/function.register-shutdown-function.php