php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65223 $_SERVER, $_ENV, $_REQUEST variables missing in $GLOBALS
Submitted: 2013-07-09 10:40 UTC Modified: 2013-07-09 12:07 UTC
From: truenrush at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.4.17 OS: Debian
Private report: No CVE-ID: None
Password:
Status:
Package:
Bug Type:
Summary:
From: truenrush at gmail dot com
New email:
PHP Version: OS:

 

 [2013-07-09 10:40 UTC] truenrush at gmail dot com
Description:
------------
When i did a var_dump($GLOBALS) i was surprized, because _SERVER variable was 
missing here, but standalone _SERVER var was working fine.

According to http://www.php.net/manual/en/reserved.variables.globals.php, 
"$GLOBALS is an associative array containing references to all variables which are 
currently defined in the global scope of the script".

_SERVER is defined in global space. But it does not appear in the $GLOBALS.
I found nothing on php.net about such behaviour. 


Test script:
---------------
var_dump($GLOBALS);

Expected result:
----------------
_SERVER key exists in $GLOBALS array.

Actual result:
--------------
_SERVER key does not exist in $GLOBALS array.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-07-09 11:20 UTC] truenrush at gmail dot com
-Summary: $_SERVER variable missing in $GLOBALS +Summary: $_SERVER, $_ENV, $_REQUEST variables missing in $GLOBALS
 [2013-07-09 11:20 UTC] truenrush at gmail dot com
I also found that $_ENV and $_REQUEST vars are also missing in $GLOBALS.

_SERVER variable appears in $GLOBALS when using php in cli mode, but with web 
server i can not find it in the $GLOBALS variable
 [2013-07-09 12:00 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2013-07-09 12:00 UTC] johannes@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

super-globals (aka. auto globals) are not added to symbol tables by defaultfor performance reasons unless the parser sees need. i.e. 

<?php
$_SERVER;
print_r($GLOBALS);
?>

will list it. You can also control this using auto_gloals_jit in php.ini: http://www.php.net/manual/en/ini.core.php#ini.auto-globals-jit
 [2013-07-09 12:07 UTC] truenrush at gmail dot com
Thanks for so fast response. I was near to blow my brain up.
Now i understand how it really works inside. Cool feature! :)
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC