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.php
And 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?
$GLOBALS is a PHP super global variable which is used to access global variables from anywhere in the PHP script (also from within functions or methods). PHP stores all global variables in an array called $GLOBALS[index]. The index holds the name of the variable.
$_SERVER is a PHP super global variable which holds information about headers, paths, and script locations.
$_SERVER is an array containing information such as headers, paths, and script locations. The entries in this array are created by the web server. There is no guarantee that every web server will provide any of these; servers may omit some, or provide others not listed here.
$_SERVER['REQUEST_URI'] contains the URI of the current page. So if the full path of a page is https://www.w3resource.com/html/html-tutorials.php, $_SERVER['REQUEST_URI'] would contain /html/html-tutorials. php.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With