php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18516 Variable-variables referencing a superglobal in a function don't work
Submitted: 2002-07-23 19:14 UTC Modified: 2002-07-23 21:17 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dilbert at hack3r dot com Assigned:
Status: Not a bug Package: Variables related
PHP Version: 4.2.2 OS: All
Private report: No CVE-ID: None
 [2002-07-23 19:14 UTC] dilbert at hack3r dot com
<? $h= "_GET";
   print_r($$h);
   echo "<hr>";
   function g() { print_r($_GET); }
   g();
   echo "<hr>";
   function t() { $g= "_GET"; print_r($$g); }
   t();
   echo "<hr>";
   $h = "hi";
   function b() { global $h; $g = "h"; print_r($$g); }
   b();
?>

I've reported a similiar bug earlier (but forgot to include something trivial in the test script and thought it was a larger one than it is... i was rebuffed, it was marked bogus, and nobody seems to pay attention to "bogus" bugs)

In the function above:

The first print_r works as expected, verifying that variable-variable referencing DOES work.

The g() function works as expected, verifying that superglobals are available in function scope.

The t() function seems to do NOTHING, this is where the bug seems to be.

The b() function works as expected, verifying that it works with regular globals.
--

This has been tested and observed on OpenBSD and linux, with PHP versions 4.2.1 and 4.2.2

Ted

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-08-04 19:56 UTC] mr dot nobody at nowhereville dot com
I can't get the $_GET or any version there of to give me anything...

If I pass(http://localhost/index.php?P=1&T=2) I expect to get them like...

$P=$_GET['P'];

I have tried several way to get them but nothing is ever displayed..

Here are ways I have tried to display..

        $var_http_get = 'HTTP_GET_VARS';
        $local_http_get = $$var_http_get;
        print $local_http_get['P'] . '*<BR>';

        echo "<br><hr>";
  	$h = "_GET";
        foreach($$h as $Value)
        {
            print $Value;
        }
        echo "<br><hr>";

        foreach($_GET as $Value)
        {
            print "GET=" . $Value . "<BR>";
        }
        echo "<br><hr>";

All pull nothing..

If I run on $_SERVER I get this

SERVER (REQUEST_METHOD) - GET
SERVER (SCRIPT_NAME) - /INDEX.PHP
SERVER (REQUEST_URI) - /INDEX.PHP?P=3&ID=413
SERVER (REQUEST_LINE) - GET /INDEX.PHP?P=3&ID=413 HTTP/1.1

So I see the data is being passed into but I can not get to it.

Windows XP(Home), Viking 1.8 Webserver, PHP 4.2.2
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC