Unsetting doesn't leave user defined variables. Unsetting simply destroys
> variables (or removes elements from an array, etc). There is nothing magic
> or hidden in that script. I think the note meant exactly what it said: after
> creating a local copy of the $GLOBALS array and removing super globals from
> it, all that's left in it are user defined variables. And that's exactly
> what gets returned from the function.
This is a script vars.php
<?php
function globals() {
$globals = $GLOBALS;
print_r("Before...");
print_r($globals);
foreach (array(
'GLOBALS',
'_ENV',
'HTTP_ENV_VARS',
'_POST',
'HTTP_POST_VARS',
'_GET',
'HTTP_GET_VARS',
'_COOKIE',
'HTTP_COOKIE_VARS',
'_SERVER',
'HTTP_SERVER_VARS',
'_FILES',
'HTTP_POST_FILES',
'_REQUEST'
) as $var) {
unset($globals[$var]);
}
print("<br />After...");
print_r($globals);
return $globals;
}
globals();
?>
I called http://localhost/vars.php?a=1
I get : -
Before...Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET]
=> Array ( [a] => 1 ) [_COOKIE] => Array ( ) [_FILES] => Array ( ) )
After...Array ( )
ALL the variables are UNSET. I have a user defined $_GET[a] but that goes
away too.
One second, what do you mean by user defined variables? Maybe I am lost in
comprehension