== Quote from Red Wingate ([EMAIL PROTECTED])'s article > Is the removal of a specific order on the __destruct() calls > necessary? It's a pain in the ass the be unable to predict > in which order the __destruct() calls are made.
I did the following test: <? class C { function __construct($n) { $this->n = $n; } function __destruct() { print $this->n . '-'; } } for ($i = 0; $i < 10; $i++) $t[] = new C($i); $t[5]->o = $t[1]; // 5 should be deleted before 1 $t[8]->o = $t[5]; // 8 should be deleted before 5 (so 1) ?> The destruction order (0-1-2-3-4-5-6-7-8-9) does not respect the dependences. This is the current implementation. But when I execute the following: <? class C ... function f() { for ($i = 0; $i < 10; $i++) $t[] = new C($i); $t[5]->o = $t[1]; // 5 must be deleted before 1 $t[8]->o = $t[5]; // 8 must be deleted before 5 (and 1) } f(); ?> The result is '0-2-3-4-6-7-8-5-1-9', the objects are destroyed in an order that respects the dependences. If I now do a circular reference ($t[1]->o = $t[5]), these 2 objects (1 and 5) are not destroyed at the end of f(), like the others, but at the end of script (like global objects). Couldn't PHP implement global object destruction that way: * firstly try to destroyed them in the same way as for local variables (respecting dependences), * for objects that were not destroyed in the first step (certainly circular references), destroy them as currently implemented (no dependence check). A notice could also be displayed. Stephane -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php