note 84720 rejected from function.unset by mgf
| From: | mgf@php.net | Date: | Mon, 28 Jul 2008 09:13:29 +0000 |
| Subject: | note 84720 rejected from function.unset by mgf | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142841@lists.php.net to get a copy of this message | ||
Note Submitter: wendymcf
----
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
?>