PHP 4.0 Bug #6962 Updated: Unsetting a global object in a function doesn't affect other functions
| From: | Bug Database | Date: | Sun, 01 Oct 2000 10:21:15 +0000 |
| Subject: | PHP 4.0 Bug #6962 Updated: Unsetting a global object in a function doesn't affect other functions | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-33938@lists.php.net to get a copy of this message | ||
ID: 6962
User Update by: rubein@earthlink.net
Status: Open
Bug Type: Scripting Engine problem
Description: Unsetting a global object in a function doesn't affect other functions
Workaround:
Change:
unset($object);
to:
unset($object);
unset($GLOBALS["object"]);
It seems that while changes to the object affect the global instance of it, unsetting it simply
removes the global alias from the script. While my suggested workaround works, it would definitely
appear to be a bug.
I'm poking into the source and taking a look at this one, but I don't understand the PHP
source that well. I'm curious now though.
Previous Comments:
---------------------------------------------------------------------------
[2000-09-30 15:57:46] rubein@earthlink.net
script:
<?
class TEST {
var $foo;
}
function one()
{
global $object;
$object = new TEST();
$object->foo = "bar";
echo "none() dump of object before unsetn";
var_dump($object);
unset($object);
echo "none() dump of object after unsetn";
var_dump($object);
two();
}
function two()
{
global $object;
echo "ntwo() dump of object after unsetn";
var_dump($object);
}
echo "<PRE>n";
one();
echo "n(no function) dump of object after unsetn";
var_dump($object);
produces:
one() dump of object before unset
object(test)(1) {
["foo"]=>
string(3) "bar"
}
one() dump of object after unset
NULL
two() dump of object after unset
object(test)(1) {
["foo"]=>
string(3) "bar"
}
(no function) dump of object after unset
object(test)(1) {
["foo"]=>
string(3) "bar"
}
unset()ing an globally defined object within a function doesn't unset it globally - it can
still be referred to in other functions.
---------------------------------------------------------------------------
Full Bug description available at: http://bugs.php.net/?id=6962