note 84720 added to function.unset
| From: | wendymcf at osu1 dot php dot net | Date: | Sun, 27 Jul 2008 16:42:00 +0000 |
| Subject: | note 84720 added to function.unset | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-142812@lists.php.net to get a copy of this message | ||
According to the Manual: If you would like to unset() a global variable inside of a function, you
can use the $GLOBALS array.
But the results, as tested below, are surprising.
<?php
$weekdays = array('Monday', 'Tuesday', 'Wednesday',
'Thursday', 'Friday');
function destroy_a_global()
{
unset($_GLOBALS['weekdays']);
print "++++++ weekdays inside of function" . PHP_EOL;
print_r($weekdays); // it's gone
print "++++++ _GLOBALS['weekdays'] inside of function" . PHP_EOL;
print_r($_GLOBALS['weekdays']); // it's gone
}
destroy_a_global();
print "++++++ weekdays outside of function" . PHP_EOL;
print_r($weekdays); // it's back
print "++++++ _GLOBALS['weekdays'] outside of function" . PHP_EOL;
print_r($_GLOBALS['weekdays']); // it's gone
?>
----
Server IP: 64.71.164.2
Probable Submitter: 84.44.226.119
----
Manual Page -- http://www.php.net/manual/en/function.unset.php
Edit -- https://master.php.net/note/edit/84720
Del: integrated -- https://master.php.net/note/delete/84720/integrated
Del: useless -- https://master.php.net/note/delete/84720/useless
Del: bad code -- https://master.php.net/note/delete/84720/bad+code
Del: spam -- https://master.php.net/note/delete/84720/spam
Del: non-english -- https://master.php.net/note/delete/84720/non-english
Del: in docs -- https://master.php.net/note/delete/84720/in+docs
Del: other reasons-- https://master.php.net/note/delete/84720
Reject -- https://master.php.net/note/reject/84720
Search -- https://master.php.net/manage/user-notes.php