I have come across the following three lines of code:
$_SERVER;
$_ENV;
$_REQUEST;
To me it seems like these three lines of code do nothing. They don't cause any errors.
I know what these three global variables are, I just don't know what these three lines of code are doing. Can anyone enlighten me?
The whole file - in case it's relevant:
<?PHP
function register_global_array( $sg ) {
Static $superGlobals = array(
'e' => '_ENV' ,
'g' => '_GET' ,
'p' => '_POST' ,
'c' => '_COOKIE' ,
'r' => '_REQUEST' ,
's' => '_SERVER' ,
'f' => '_FILES'
);
Global ${$superGlobals[$sg]};
foreach( ${$superGlobals[$sg]} as $key => $val ) {
$GLOBALS[$key] = $val;
}
}
function register_globals( $order = 'gpc' ) {
$_SERVER; //See Note Below
$_ENV;
$_REQUEST;
$order = str_split( strtolower( $order ) );
array_map( 'register_global_array' , $order );
}
register_globals('GPCFRES');
?>
And no, there isn't any note below.
They clearly do something because if I remove them, then the foreach line errors.
$_GLOBALS['_SERVER']
before using$_SERVER
, it will returnnull
.${$SuperGlobals...}
.$GLOBALS
and not$_GLOBALS
. I can't find it now, but there was a comment somewhere on php.net explaining that sometimes the superglobals wouldn't be available for exporting/debugging/access over$GLOBALS
. I can't find it now.