Posted by Michael Fesser on 09/16/07 11:36
..oO(Sanders Kaufman)
>Michael Fesser wrote:
>
>> | Please note that variable variables cannot be used with PHP's
>> | Superglobal arrays within functions or class methods.
>
>I read that, and re-read it, and re-read it... and I can't figure out
>what it means. Can you re-phrase it?
>
>I was good right up to "within functions...". I use super globals
>within functions all the time.
A variable variable is something like that:
$foo = 'bar';
$bar = 42;
print ${$foo}; // prints 42
This means the name of the variable is taken from another (string)
variable. The same can be done with superglobals, but not if you're
inside a function or method:
function test() {
$foo = '_GET';
var_dump(${$foo}); // throws a notice
}
Micha
[Back to original message]
|