From: feldgendler at mail dot ru Operating system: PHP version: 5.0.4 PHP Bug Type: Zend Engine 2 problem Bug description: Destructor order for global objects
Description: ------------ If several objects are created in the global scope, their destructors are called in the same order the objects were created, not in the reverse order. PHP documentation does not promise anything certain about the order in which destructors are called, but the common practice for many object-oriented languages is to call the destructors in the reverse order. This usually (though not always) is better in cases when the objects being destroyed depend on each other. I think that the order of destructor calls for global objects should be reverse compared to the order of their creation. Actually, the same is already true for function local variables. Reproduce code: --------------- class C1 { function __construct() { print "Constructing " . get_class($this) . "\n"; } function __destruct() { print "Destroying " . get_class($this) . "\n"; } } class C2 { function __construct() { print "Constructing " . get_class($this) . "\n"; } function __destruct() { print "Destroying " . get_class($this) . "\n"; } } $c1 = new C1(); $c2 = new C2(); Expected result: ---------------- Constructing C1 Constructing C2 Destructing C2 Destructing C1 Actual result: -------------- Constructing C1 Constructing C2 Destructing C1 Destructing C2 -- Edit bug report at http://bugs.php.net/?id=33348&edit=1 -- Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=33348&r=trysnapshot4 Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=33348&r=trysnapshot50 Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=33348&r=trysnapshot51 Fixed in CVS: http://bugs.php.net/fix.php?id=33348&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=33348&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=33348&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=33348&r=needscript Try newer version: http://bugs.php.net/fix.php?id=33348&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=33348&r=support Expected behavior: http://bugs.php.net/fix.php?id=33348&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=33348&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=33348&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=33348&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=33348&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=33348&r=dst IIS Stability: http://bugs.php.net/fix.php?id=33348&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=33348&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=33348&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=33348&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=33348&r=mysqlcfg