|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Dec 12 17:00:01 2025 UTC |
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.