ID: 43080 Updated by: [EMAIL PROTECTED] Reported By: joustin at post dot pl -Status: Assigned +Status: Bogus Bug Type: Class/Object related Operating System: * PHP Version: 5.2.4 Assigned To: dmitry New Comment:
The foo::__destruct() is called during destruction of global variable $foo. The folowing script is a simplified example and its behavior was never changed. <?php class foo { function __destruct() { global $foo; var_dump($foo); // prints NULL, because $foo is alredy destoied } } $foo = new foo(); unset($foo); ?> php-5.2.4 just makes unset() for objects automaticly (in right order). Previous Comments: ------------------------------------------------------------------------ [2007-10-25 13:28:14] [EMAIL PROTECTED] Dmitry, can you check this out please. ------------------------------------------------------------------------ [2007-10-25 13:06:54] joustin at post dot pl Upgraded from 5.2.3 to 5.2.4. I could not find any reference to if (and why) it would change. Changelog gives no clue either. It happens to globally defined vars - php engine nulls the reference to object before calling it's destructor. IMO illogical and inconsistent. Worked fine before 5.2.4. ------------------------------------------------------------------------ [2007-10-25 12:55:59] [EMAIL PROTECTED] Upgraded from what PHP version..? AFAIK, this is how it should work, so I don't understand why you report a bug about it.. ------------------------------------------------------------------------ [2007-10-23 10:43:02] joustin at post dot pl Description: ------------ This is quite interesting. Appeared after upgrading to 5.2.4 and broke my code. It's great that objects are finally destroyed in the right order, but a whole lot of code still relies on "destroy all" or "cleanup" functions. What struck me is that as of 5.2.4, my object in the moment of calling it's destructor, in global scope, appears as NULL. I've also devised a simple and dirty workaround, which is found in the code below. Thanks! Reproduce code: --------------- class foo { function __construct(){ echo "Constructed foo\n"; } function getDb(){ echo "Getting DB"; } function __destruct(){ echo "Destructing foo\n"; echo "Trying to destruct bar\n"; global $bar; if(false){ // DIRTY WORKAROUND global $foo; $foo = $this; } $bar->__destruct(); } } class bar { protected $destroyed = false; function __construct(){ echo "Constructed bar\n"; } function __destruct(){ if(!$this->destroyed){ echo " Destructing bar\n"; global $foo; echo " Our global parent, foo, is of type ".gettype($foo)."\n"; $this->destroyed = true; } } } $bar = new bar(); $foo = new foo(); echo "--\nScript finishes...\n"; Expected result: ---------------- Constructed bar Constructed foo -- Script finishes... Destructing foo Trying to destruct bar Destructing bar Our global parent, foo, is of type object Actual result: -------------- Constructed bar Constructed foo -- Script finishes... Destructing foo Trying to destruct bar Destructing bar Our global parent, foo, is of type NULL ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=43080&edit=1