note 8349 modified in unset by jmcastagnetto
| From: | jmcastagnetto@php.net | Date: | Thu, 07 Sep 2000 21:33:46 +0000 |
| Subject: | note 8349 modified in unset by jmcastagnetto | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-4450@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']);
http://www.php.net/manual/function.unset.php