From: ozone at cname dot com
Operating system: linux 2.6.13.2
PHP version: 5.1.2
PHP Bug Type: Variables related
Bug description: variable variable reference to superglobal only works after
non-variable ref
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.
--
Edit bug report at http://bugs.php.net/?id=36018&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=36018&r=trysnapshot44
Try a CVS snapshot (PHP 5.1):
http://bugs.php.net/fix.php?id=36018&r=trysnapshot51
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=36018&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=36018&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=36018&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=36018&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=36018&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=36018&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=36018&r=support
Expected behavior: http://bugs.php.net/fix.php?id=36018&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=36018&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=36018&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=36018&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=36018&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=36018&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=36018&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=36018&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=36018&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=36018&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=36018&r=mysqlcfg