php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #691 $GLOBALS does not work with array elements
Submitted: 1998-08-24 22:05 UTC Modified: 1998-08-24 22:28 UTC
From: charly at openware dot com dot ar Assigned:
Status: Closed Package: Other
PHP Version: 3.0.3 OS: SCO OSE 5.0.2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: charly at openware dot com dot ar
New email:
PHP Version: OS:

 

 [1998-08-24 22:05 UTC] charly at openware dot com dot ar
Hi. I have the following piece of code:
===========
function pp( $var ) {
        echo $GLOBALS[$var];
}

$ab= "hello";
echo pp( "ab" );
===========
This returns "hello".

But, the following piece of code does not work.
===========
function pp( $var ) {
        echo $GLOBALS[$var];
}

$ab[1]= "hello";          <- I've added [1]
echo pp( "ab[1]" );      <- also here
===========
This returns "".

I have also tryied with a little different code.
===========
function pp( $var ) {
        global $$var;
        echo "${$var}";
}

$ab= "hello";
echo pp( "ab" );
===========
This returns "hello".

But it does not work too with an array element like this:
===========
function pp( $var ) {
        global $$var;
        echo "${$var}";
}

$ab[1]= "hello";
echo pp( "ab[1]" );
===========
This returns "".

I've looked for a bug in the bug database but I didn't found one. Excuse me it is not a bug.

Regards, Carlos.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-08-24 22:28 UTC] rasmus
No bug here.  To get $ab[1] from the GLOBALS array you have to use $GLOBALS["ab"][1] and in your second case if $var="ab" then you can do a global $$var and then echo ${$var}[1]
This doesn't solve your problem, but it explains how it works.
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Tue Sep 27 21:05:53 2022 UTC