Re: Using Superglobals for variable variables works

From: Date: Fri, 28 Jan 2005 23:53:44 +0000
Subject: Re: Using Superglobals for variable variables works
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-14452@lists.php.net to get a copy of this message
yep, figured it out already. Problem is the german version of the manual. It is wrong and doesn't say anything about functions and methods. It simply says you can't use superglobals for variable variable and uses a illogical example ${$_GET}, whatever that should mean ;). The english manual is right though and says you can't use it in functions and methods. Thanks anyway, Michael Sara Golemon wrote:
but this does also work, atm. i'm using PHP 5.0.2 on Windows XP with apache 1.3 and if i call my php page with http://localhost/test.php?test=works it works. //test.php <?php $a = '_GET'; echo ${$a}['test']; var_dump($$a); ?>
It works when you're already at the global scope, but try this: <?php function foo() { var_dump($_GET); $g = '_GET'; var_dump($$g); } foo(); ?> The first var_dump() will work right because $_GET is a superglobal and ZE picks it out of the global context correctly, the second var_dump() will yield a NULL and an undefined index since it will try to access it from the local symbol table and not find it. Declaring a variable as superglobals is just a hint to the scripting engine to retreive it from the global symbol table rather than the active symbol table (Superglobals, by definition live in the global symbol table). Your example worked because at the time the variable variable was resolved, the global symbol table WAS the active symbol table. -Sara


« previous php.internals (#14452) next »