note 25427 rejected from function.unset by victor
| From: | victor@php.net | Date: | Mon, 23 Sep 2002 17:57:22 +0000 |
| Subject: | note 25427 rejected from function.unset by victor | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-37156@lists.php.net to get a copy of this message | ||
unset() seems to be buggy when used inside functions on global-ized variables.
This piece of code:
----8<----8<----
function foo()
{
global $bar;
unset($bar);
}
$bar = "initial value";
foo();
if(isset($bar))echo "bar has ".$bar." after foo\n";
else echo "bar has no value after foo\n";
----8<----8<----
has this output:
----8<----8<----
bar has initial value after foo
----8<----8<----
If there is some other function called from inside of foo() (after unset) and if this function also
globalizes bar and assings it some new value, this new value is then set correctly. Example:
----8<----8<----
function foofoo()
{
global $bar;
$bar = "a value from foofoo()"
}
function foo()
{
global $bar;
unset($bar);
foofoo();
}
$bar = "initial value";
foo();
if(isset($bar))echo "bar has ".$bar." after foo\n";
else echo "bar has no value after foo\n";
----8<----8<----
has this output:
----8<----8<----
bar has a value from foofoo() after foo
----8<----8<----