php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32585 Superglobals behave differently inside functions
Submitted: 2005-04-05 11:47 UTC Modified: 2005-04-05 11:52 UTC
From: c dot i dot morris at durham dot ac dot uk Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.10 OS: Linux
Private report: No CVE-ID: None
 [2005-04-05 11:47 UTC] c dot i dot morris at durham dot ac dot uk
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:



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-05 11:52 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

That\'s the way it works... 
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC