On Fri, Nov 20, 2009 at 12:28 AM, Arno Kuhl <akuhl@xxxxxxxxxxxx> wrote: > -----Original Message----- > From: Ford, Mike [mailto:M.Ford@xxxxxxxxxxxxxx] > Sent: 19 November 2009 07:06 PM > To: php-general@xxxxxxxxxxxxx > Subject: RE: Using $$ > >> -----Original Message----- >> From: Arno Kuhl [mailto:akuhl@xxxxxxxxxxxx] >> Sent: 19 November 2009 12:23 >> >> I was looking at some old code that I'm convinced once worked but now >> using >> php5 it doesn't seem to work anymore. >> >> $input = "_REQUEST"; >> if (is_array($$input)) { >> // do something >> } > > >> I tested something other than a superglobal and it works as expected. >> What am I missing? > > > Depends where you have this fragment of code, but possibly the big fat > warning box towards the bottom of > http://php.net/language.variables.variable? > > Cheers! > > Mike > -- > > Thanks for the link Mike, didn't know that. It doesn't say when this was > introduced but I'm sure superglobal variable variables must have worked at > some stage, because I've got code that once worked but doesn't anymore and > it's due to this. There's always a workaround, just not as elegant. > > Cheers > Arno > > The problem got me curious, so I got hackin. The workaround in functions and methods is to access it through the $GLOBALS superglobal array. Here's some code I threw together in an interactive PHP terminal. php > function test_nowork($vn) { var_dump($$varname);} php > test_nowork('_ENV'); NULL php > function test_work($vn) { var_dump($GLOBALS[$vn]); } php > test_work('_ENV'); array(##) { ["ORBIT_SOCKETDIR"]=>... ["SSH_AGENT_PID"]=>... ["GPG_AGENT_INFO"]=>... ["TERM"]=>... ["SHELL"]=>... ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php