From: luke at cywh dot com Operating system: Linux PHP version: 5.2.6 PHP Bug Type: Scripting Engine problem Bug description: destruct in wrong order with static object
Description: ------------ This is related to a bug that was fixed in version 5.2.0, which you can read about here: http://bugs.php.net/bug.php?id=36759 Basically if you were to initiate a class, the destruct order would be incorrect: "C1,C2,C3,D1,D2,D3". This was corrected in 5.2.0 to be "C1,C2,C3,D3,D2,C1". The problem, however, still persists if you create an object inside a static object. Code to recreate this issue is included in this bug report. If you initiate the classes without the Registry singleton, it destructs properly ($c1 = new class1()...). Testing this with 5.1.6, the destruct order is incorrect in both situations (as i'd expect). If you unset the objects in reverse order as they were created, both work correctly on 5.1.6 and 5.2.6. So a work-around for either version is to simply track the objects and unset them. But if you don't do this, the destruct order is still incorrect if creating your objects through a singleton object. Reproduce code: --------------- class shorten { public function __construct() { print 'C:' . get_class($this) . "<br />"; } public function __destruct() { print 'D:' . get_class($this) . "<br />"; } } class class1 extends shorten {} class class2 extends shorten {} class class3 extends shorten {} class Registry { static private $instance = null; private $registered = array(); static public function instance() { if(self::$instance == null) self::$instance = new Registry(); return self::$instance; } private function __call($name, $arguments) { if( ! isset($this->registered[$name]) ) $this->registered[$name] = new $name(); return $this->registered[$name]; } private function __get($name) { if( ! isset($this->registered[$name]) ) $this->registered[$name] = new $name(); return $this->registered[$name]; } } Registry::instance()->class1(); Registry::instance()->class2(); Registry::instance()->class3(); Expected result: ---------------- C:class1 C:class2 C:class3 D:class3 D:class2 D:class1 Actual result: -------------- C:class1 C:class2 C:class3 D:class1 D:class2 D:class3 -- Edit bug report at http://bugs.php.net/?id=46169&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=46169&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=46169&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=46169&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=46169&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=46169&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=46169&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=46169&r=needscript Try newer version: http://bugs.php.net/fix.php?id=46169&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=46169&r=support Expected behavior: http://bugs.php.net/fix.php?id=46169&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=46169&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=46169&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=46169&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=46169&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=46169&r=dst IIS Stability: http://bugs.php.net/fix.php?id=46169&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=46169&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=46169&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=46169&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=46169&r=mysqlcfg