note 8349 deleted from unset by danbeck
| From: | danbeck@php.net | Date: | Wed, 20 Sep 2000 09:16:22 +0000 |
| Subject: | note 8349 deleted from unset by danbeck | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-5215@lists.php.net to get a copy of this message | ||
[Editor's note: merged Jon's annotations]
Beware! If you are in a function and the variable is a global you are accessing using
'global', then unset does not work. It simply un-globalises the variable, instead of
unsetting the global. This changed between PHP3 and PHP4.
It appears that unset($GLOBALS['foo']) might be the right way to go now.
It is actually even subtler than that. If you have a situation where
before, you were doing:
global $foo;
unset($foo);
Then changing it to:
global $foo;
unset($GLOBALS['foo']);
will not unset the local $foo.
The correct fix is:
unset($GLOBALS['foo']);
global $foo;
or
global $foo;
unset($foo);
unset($GLOBALS['foo']);