From: c dot i dot morris at durham dot ac dot uk
Operating system: Linux
PHP version: 4.3.10
PHP Bug Type: Scripting Engine problem
Bug description: Superglobals behave differently inside functions
Description:
------------
When constructing a variable name using the $$foo syntax, it is only
possible to reference a superglobal in this way from outside a function.
Inside a function it appears to reference a variable with the same name
that is local to the function.
In other words, the code
$foo='_REQUEST';
print (${$foo}['bar']);
behaves differently within a function and within the main loop.
I've been able to reproduce this bug on several servers with different
configurations. 4.3.10 is the latest version I have available to test.
Reproduce code:
---------------
Demonstration
http://www.dur.ac.uk/c.i.morris/superglobals.php?foo=123
Source code
http://www.dur.ac.uk/c.i.morris/superglobals.phps
[Note: this server is running an older version of PHP, but the same
effect happens on a non-public server running 4.3.10]
Expected result:
----------------
Out of the function:123
In the function:123
Actual result:
--------------
Out of the function:123
In the function:
--
Edit bug report at http://bugs.php.net/?id=32585&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=32585&r=trysnapshot4
Try a CVS snapshot (php5.0):
http://bugs.php.net/fix.php?id=32585&r=trysnapshot50
Try a CVS snapshot (php5.1):
http://bugs.php.net/fix.php?id=32585&r=trysnapshot51
Fixed in CVS: http://bugs.php.net/fix.php?id=32585&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=32585&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=32585&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=32585&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=32585&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=32585&r=support
Expected behavior: http://bugs.php.net/fix.php?id=32585&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=32585&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=32585&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=32585&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=32585&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=32585&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=32585&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=32585&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=32585&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=32585&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=32585&r=mysqlcfg