php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50929 Incorrect initialization of $_SERVER
Submitted: 2010-02-03 18:12 UTC Modified: 2010-02-03 18:42 UTC
From: t-bader at gmx dot net Assigned:
Status: Not a bug Package: Variables related
PHP Version: 5.3.1 OS: Windows Vista/7
Private report: No CVE-ID: None
 [2010-02-03 18:12 UTC] t-bader at gmx dot net
Description:
------------
The manual says that Superglobals can be referenced by variable variables in global scope.

For the $_SERVER superglobal does this only work at it first "normal" usage.

<?php
$Superglobal = '_SERVER';
var_dump($$Superglobal);
?> 

Outputs: NULL

But if i use the $_SERVER Variable after the var_dump(); the var_dump()s output is correct:

<?php
$Superglobal = '_SERVER';
var_dump($$Superglobal);

$_SERVER;

var_dump($$Superglobal);
?> 

Both var_dump()s output the whole $_SERVER array. If i remove the line with $_SERVER; both var_dump()s output is NULL.


Reproduce code:
---------------
<?php
$Superglobal = '_SERVER';
var_dump($$Superglobal);
?> 

Expected result:
----------------
Array containing the $_SERVER variables

Actual result:
--------------
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-02-03 18:42 UTC] jani@php.net
You have just discovered JIT initialization of superglobals:

http://www.php.net/manual/en/ini.core.php#ini.auto-globals-jit

(note the Warning there..)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat May 18 21:01:33 2024 UTC