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@xxxxxxxxxxxxx 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
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php