|
Posted by mannerboy on 11/17/06 05:52
maybe i guess , once overload the function __destruct() , you should
destruct the object explicitly...
i havn't written a script to test this .....
"Thomas Mlynarczyk 写道:
"
> Hi,
>
> I have this code:
>
> class Test
> {
> public $status = 'dead';
> function __construct() { $this->status = 'alive'; }
> function __destruct() { echo '<br>__destruct()'; }
> }
> $o = new Test;
>
> function shutdown()
> {
> echo '<br>shutdown()';
> }
> register_shutdown_function('shutdown');
>
> function obflush( $s )
> {
> global $o;
> return $s . '<br>obflush() ' . $o->status;
> }
> ob_start('obflush');
>
> Which (using PHP 5.1.4) produces this output:
>
> shutdown()
> __destruct()
> obflush() alive
>
> I have two questions:
>
> 1) I have read that the order in which the three functions are called has
> changed previously and is likely to change again in future versions of PHP.
> Does this mean I cannot rely on this order at all?
>
> 2) Why is $o still "alive" in obflush() even though its destructor has been
> called before? The destructor having been called, I would expect global $o
> to point to a no longer existing variable (thus, "null").
>
> Greetings,
> Thomas
Navigation:
[Reply to this message]
|