You are here: Re: [PHP] Reverse destruction « PHP « IT news, forums, messages
Re: [PHP] Reverse destruction

Posted by Jochem Maas on 01/02/06 14:33

Mattias Segerdahl wrote:
> Is it possible to reverse class __destruct() instead of following the class
> initiations? It makes more sence to me to close objects in last start first
> close.

why don't you go and read up on request shutdown issues and __destruct() -
there is plenty in the archives of the internals@lists.php.net mailing list;
it's many times more complex than you might imagine (imagine 2 'chicken & egg'
problems in tandem - oh and a solution is needed to handle circular references
properly so that object refcounts behave the way you would expect with regard to
triggering dtor functions). bottom line don't hold your breath if you want the
__destruct() and shutdown code/beahviour changed.

*
* tell us why do you want to control the descruction order of your objects?
* it might help someone offer a viable alternative
*

btw: stating a new post/thread by replying to an existing one is very bad
form - given that you have knowledge of ctors/dtors in php your skill
level is probably greta enough that you should know better ;-)


>
> <?php
> class Class1 {
> function __construct() {
> echo 'Constructing ' . __CLASS__ . "\n";
> }
>
> Function __destruct() {
> echo 'Destructing ' . __CLASS__ . "\n";
> }
> }
>
> class Class2 {
> function __construct() {
> echo 'Constructing ' . __CLASS__ . "\n";
> }
>
> Function __destruct() {
> echo 'Destructing ' . __CLASS__ . "\n";
> }
> }
>
> class Class3 {
> function __construct() {
> echo 'Constructing ' . __CLASS__ . "\n";
> }
>
> Function __destruct() {
> echo 'Destructing ' . __CLASS__ . "\n";
> }
> }
>
> $Class1 = new Class1();
> $Class2 = new Class2();
> $Class3 = new Class3();
> ?>
>
> Would output,
>
> Constructing Class1
> Constructing Class2
> Constructing Class3
> Destructing Class1
> Destructing Class2
> Destructing Class3
>
> I'd like for it to do:
>
> Constructing Class1
> Constructing Class2
> Constructing Class3
> Destructing Class1
> Destructing Class2
> Destructing Class3 Constructing Class1
> Constructing Class2
> Constructing Class3
> Destructing Class3
> Destructing Class2
> Destructing Class1
>
> Destructing the last started object first
>

 

Navigation:

[Reply to this 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

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