PHP 4.0 Bug #3647: Change to Global variable in Function Fails
| From: | pour at mieterra dot com | Date: | Mon, 28 Feb 2000 10:09:40 +0000 |
| Subject: | PHP 4.0 Bug #3647: Change to Global variable in Function Fails | ||
| Groups: | php.dev | ||
| Request: | Send a blank email to php-dev+get-16089@lists.php.net to get a copy of this message | ||
From: pour@mieterra.com
Operating system: Linux 2.2.x
PHP version: 4.0 Beta 4 Patch Level 1
PHP Bug Type: Scripting Engine problem
Bug description: Change to Global variable in Function Fails
Changing a Global variable in a function fails when the Global variable is unset. An easy example:
<?php
class test { var $a="a here"; var $b = "b here"; }
$t = new test;
$t->a = "b here";
function changeGlobal()
{
GLOBAL $t;
unset($t);
$t = new test;
}
echo "t->a = $t->a\n";
changeGlobal();
echo "t->a = $t->a\n";
?>
When executed, this displays:
t->a = b here
t->a = b here
proving that the new assignment to 't' in changeGlobal had no effect.
Note that the result is correct if using GLOBALS["t"] in changeGlobal; it also works when
removing the 'unset' statement in changeGlobal or redeclaring "GLOBAL $t" right
after the unset. Presumably the function forgets the scope of 't' after the unset is
executed.
Regards,
Andreas