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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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-2024 The PHP Group
All rights reserved.
Last updated: Sat Apr 20 04:01:28 2024 UTC