ID: 43080
Updated by: [EMAIL PROTECTED]
Reported By: joustin at post dot pl
-Status: Open
+Status: Feedback
Bug Type: Class/Object related
Operating System: win32
PHP Version: 5.2.4
New Comment:
Upgraded from what PHP version..? AFAIK, this is how it should work, so
I don't understand why you report a bug about it..
Previous Comments:
------------------------------------------------------------------------
[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