Reputation: 383
i have following code.
$hello = "World";
$test = "hello";
echo $$test;
When I execute this I get as result: World
So far as good
But when I use a reserved variable, for example $_GET it doesn't work.
$test = "_GET";
var_dump($$test);
Here the result is NULL. Is there a way to get values of a reserved variable throught a variable variable?
Upvotes: 2
Views: 53
Reputation: 53533
Superglobals can only be dereferenced by variable variables in the global scope. The fact you can't get it to work seems to indicate that your code is in a function/method. In this case, you can use the $GLOBALS
superglobal:
function foo() {
$str = '_GET';
var_dump($GLOBALS[$str]);
}
foo();
Upvotes: 2