#30823 [Bgs]: Objects destroyed in FIFO rather LIFO.

From: Date: Fri, 22 Apr 2005 07:34:21 +0000
Subject: #30823 [Bgs]: Objects destroyed in FIFO rather LIFO.
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-78047@lists.php.net to get a copy of this message
ID: 30823 User updated by: richard dot quadling at bandvulc dot co dot uk Reported By: richard dot quadling at bandvulc dot co dot uk Status: Bogus Bug Type: Class/Object related Operating System: * PHP Version: 5CVS-2005-03-06 Assigned To: andi New Comment: Ah. What I was looking for was this construct ... try { $obj = new An_Object(); // Creating ALWAYS works. try { // do work } catch (Exception $e) { echo 'Something went quite wrong : ' . $e->getMessage() . "\n"; } } finally { unset($obj}; // No matter what, ALWAYS destroy the object. } With no finally, I got tangled. Richard. Previous Comments: ------------------------------------------------------------------------ [2005-04-22 09:29:47] richard dot quadling at bandvulc dot co dot uk Ah. What the answer should have been is to use unset() on the object reference. I saw a forest and forgot my chainsaw. Sorry for wasting time. But, I do think that unhandled objects should be destroyed LIFO. Richard. ------------------------------------------------------------------------ [2005-04-22 00:34:01] andi@php.net Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php There is no predefined order in which objects are destroyed. It is random as object id's are re-used after objects have been destroyed. There is no way (and I don't think there should be) to change this as we are efficiently using existing object space. You have to build your own mechanism (which should be quite easy) in order to order certain destruction processes. ------------------------------------------------------------------------ [2005-04-21 17:33:50] sniper@php.net Andi, is this behaviour carved into ZE2 stone or can it be changed? ------------------------------------------------------------------------ [2004-11-19 08:46:27] richard dot quadling at bandvulc dot co dot uk Nope. The output is ... destroy A destroy B Objects are destroyed in the order they are created. This is, in my opinion, bad. I would expect ... destroy B destroy A (and it took me at least 2 minutes to work out why I got nothing at all - short tags!). Richard. ------------------------------------------------------------------------ [2004-11-18 22:29:44] tony2001@php.net Please, run this code: <? class a { function __destruct() { echo "destroy A\n"; } } class b { function __destruct() { echo "destroy B\n"; } } $a = new a; $b = new b; ?> and make sure that it works as you expect. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/30823 -- Edit this bug report at http://bugs.php.net/?id=30823&edit=1

« previous php.bugs (#78047) next »