Reply to Re: Shutdown order

Your name:

Reply:


Posted by petersprc on 11/15/06 20:35

Hi Thomas,

The order in my version of PHP5.1.6 (main/main.c:php_request_shutdown):

/* 1. Call all possible shutdown functions registered with
register_shut down_function() */
....php_call_shutdown_functions(TSRMLS_C);...

/* 2. Call all possible __destruct() functions */
....zend_call_destructors(TSRMLS_C);...

/* 3. Flush all output buffers */
....php_end_ob_buffers((zend_bool)(SG(request_info).headers_only?0:1)
TSRMLS_CC)...

[...more steps...]

Maybe step 2 only invokes the destructor, leaving de-allocation to be
done later? I don't know for certain. Here's some more comments about
this:

http://www.zend.com/lists/php-dev/200509/msg00064.html


Thomas Mlynarczyk wrote:
> 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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация