php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #36018 variable variable reference to superglobal only works after non-variable ref
Submitted: 2006-01-15 06:38 UTC Modified: 2007-08-28 01:00 UTC
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: ozone at cname dot com Assigned:
Status: No Feedback Package: Documentation problem
PHP Version: 5.1.2 OS: linux 2.6.13.2
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-01-15 06:38 UTC] ozone at cname dot com
Description:
------------
environment: generic apache 2.0.55 / php 5.1.2 on linux
(can reproduce with 5.0.5 on solaris9; it's not the os)

yes, i've read the "variable variable references to superglobals aren't supported in functions"; this isn't in a function, and the behavior is very very strange.

see attached code. the var-var-refs to $_SERVER works as expected IF AND ONLY IF that superglobal is referred to elsewhere in the code by its real name -- anywhere in the code is fine, even after the var-var-ref. this behavior suggests that the $_SERVER superglobal isn't instantiated (or made available) if the interpreter decides (wrongly) that it's not necessary.

the parser does complain thusly:

PHP Warning:  Invalid argument supplied for foreach() in /home/web/docs/bug.php on line 11




Reproduce code:
---------------
<?
// works as expected if the following line is uncommented
// if(is_array($_SERVER)) echo '';
echo "<html><table border=1 cellpadding=2>";
foreach(array(  "_GET" => "#f0c0f0",
                "_POST" => "#f0c0c0",
                "_SESSION" => "#c0f0f0",  
                "_SERVER" => "#f0f0c0") as $a => $c) { 
        echo "\n<tr width=100% bgcolor=#c0c0c0><td colspan=2 align=right>$a</td></tr>";
        foreach(${$a} as $k => $v) if($k)
                echo "\n<tr><td bgcolor=$c>$k</td><td bgcolor=$c>$v</td></tr>";
}
echo "\n</table></html>";
?>


Expected result:
----------------
should have a table of all variables related to the request (i use this bit of code where i catch errors, it tends to be helpful).

Actual result:
--------------
nothing.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-15 12:12 UTC] derick@php.net
The behavior is expected. PHP will only handle super globals correctly if use their full name. The documentation is wrong on this. (The reason for this particular behavior is that PHP will only populate the super globals when they are first used, but PHP can only detect that when you're using the full name only).
 [2007-08-20 12:41 UTC] vrana@php.net
Thank you for taking the time to report a problem with PHP.
Unfortunately you are not using a current version of PHP -- 
the problem might already be fixed. Please download a new
PHP version from http://www.php.net/downloads.php

If you are able to reproduce the bug with one of the latest
versions of PHP, please change the PHP version on this bug report
to the version you tested and change the status back to "Open".
Again, thank you for your continued support of PHP.

Can you please try it in a new version?
 [2007-08-26 22:40 UTC] postings-php-bug at hans-spath dot de
I can reproduce the error message using the given code.
PHP_VERSION == "5.2.3-0.dotdeb.1"
(on Debian Etch, Kernel 2.6.18-4-686)
 [2007-08-28 01:00 UTC] phpdoc at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 14:01:22 2019 UTC