From: joustin at post dot pl
Operating system: win32
PHP version: 5.2.4
PHP Bug Type: Class/Object related
Bug description: Global object is null before destroying it.
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 bug report at http://bugs.php.net/?id=43080&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=43080&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=43080&r=trysnapshot52
Try a CVS snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=43080&r=trysnapshot53
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=43080&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=43080&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=43080&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=43080&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=43080&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=43080&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=43080&r=support
Expected behavior: http://bugs.php.net/fix.php?id=43080&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=43080&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=43080&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=43080&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43080&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=43080&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=43080&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=43080&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=43080&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=43080&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=43080&r=mysqlcfg