Using $$
am 19.11.2009 13:23:03 von Arno Kuhl
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 know $_REQUEST is an array, but $$input is NULL (I was expecting it ==
$_REQUEST).
I also tried ${$input} but same result.
I tested something other than a superglobal and it works as expected. What
am I missing?
Cheers
Arno
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Using $$
am 19.11.2009 18:05:41 von M.Ford
> -----Original Message-----
> From: Arno Kuhl [mailto:akuhl@telkomsa.net]
> Sent: 19 November 2009 12:23
>=20
> I was looking at some old code that I'm convinced once worked but
> now using
> php5 it doesn't seem to work anymore.
>=20
> $input =3D "_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 warn=
ing box towards the bottom of http://php.net/language.variables.variable?
Cheers!
Mike
--=20
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,
Leeds Metropolitan University, C507, Civic Quarter Campus,=20
Woodhouse Lane, LEEDS,=A0 LS1 3HE,=A0 United Kingdom=20
Email: m.ford@leedsmet.ac.uk=20
Tel: +44 113 812 4730
To view the terms under which this email is distributed, please go to http:=
//disclaimer.leedsmet.ac.uk/email.htm
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
RE: Using $$
am 20.11.2009 08:28:42 von Arno Kuhl
-----Original Message-----
From: Ford, Mike [mailto:M.Ford@leedsmet.ac.uk]
Sent: 19 November 2009 07:06 PM
To: php-general@lists.php.net
Subject: RE: [PHP] Using $$
> -----Original Message-----
> From: Arno Kuhl [mailto:akuhl@telkomsa.net]
> 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
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Using $$
am 22.11.2009 20:32:33 von LinuxManMikeC
On Fri, Nov 20, 2009 at 12:28 AM, Arno Kuhl wrote:
> -----Original Message-----
> From: Ford, Mike [mailto:M.Ford@leedsmet.ac.uk]
> Sent: 19 November 2009 07:06 PM
> To: php-general@lists.php.net
> Subject: RE: [PHP] Using $$
>
>> -----Original Message-----
>> From: Arno Kuhl [mailto:akuhl@telkomsa.net]
>> 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 =3D "_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 a=
t
> some stage, because I've got code that once worked but doesn't anymore an=
d
> 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"]=3D>...
["SSH_AGENT_PID"]=3D>...
["GPG_AGENT_INFO"]=3D>...
["TERM"]=3D>...
["SHELL"]=3D>...
....
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php