Reputation: 9726
According to http://www.php.net/manual/en/reserved.variables.globals.php :
An associative array containing references to all variables which are currently defined in the global scope of the script.
So, following code must display that $GLOBALS var has _SERVER
, _ENV
(if it is enabled in variables_order in php.ini) and _REQUEST
keys:
var_dump($GLOBALS);
The result is:
_SERVER
, _ENV
, _REQUEST
_ENV
, _REQUEST
Hmm.. perhaps there is smth in docs about this behavior? I've looked through every page for each variable:
_SERVER
: http://www.php.net/manual/en/reserved.variables.server.php_ENV
: http://www.php.net/manual/en/reserved.variables.request.php_REQUEST
: http://www.php.net/manual/en/reserved.variables.request.phpAnd i have found no mentions about such behaviour. Why it works like that?
I have installed php using debian package from http://www.dotdeb.org/ repo (nothing was compiled manually)... Currently running with nginx + php5-fpm. Is that a php bug?
Upvotes: 7
Views: 3880
Reputation: 9726
I've created a bug on php.net website, and php team answered: https://bugs.php.net/bug.php?id=65223
Summary:
This is not a bug. super-globals (aka. auto globals) are not added to symbol tables by default for performance reasons unless the parser sees need. i.e.
<?php $_SERVER; print_r($GLOBALS); ?>
will list it. You can also control this using auto_globals_jit in php.ini: http://www.php.net/manual/en/ini.core.php#ini.auto-globals-jit
Thanks php team so answer so fast!
Upvotes: 7