Re: Variable Variables and Superglobals
| From: | A.Rico | Date: | Thu, 05 Aug 2004 14:14:31 +0000 |
| Subject: | Re: Variable Variables and Superglobals | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-11935@lists.php.net to get a copy of this message | ||
What the PHP documentation says about variable variables and superglobals is that you can't use them as a "pointer":
/*Warning*/
/ Please note that variable variables cannot be used with PHP's
Superglobal arrays
<http://www.php.net/manual/en/language.variables.predefined.php#language.variables.superglobals>.
This means you cannot do things like ${$_GET}. If you are looking
for a way to handle availability of superglobals and the old
HTTP_*_VARS, you might want to try referencing
<http://www.php.net/manual/en/language.references.php> them. /
what I intended was to use a "normal" globally defined variable to "point" to a superglobal; that, in fact, works in the global scope, but not in the function scope:
// Code //////////////////////////////////////////////////////////////
$varvar="_ENV";
echo $_ENV["OS"]; // --> Windows NT
echo ${$varvar}; // --> Windows NT
foo($varvar);
function foo($arg){
$lvar="_ENV";
echo $_ENV["OS"]; // --> Windows NT
echo ${$arg}["OS"]; // --> *nothing*
echo ${$lvar}["OS"]; // --> *nothing*
var_dump( $$arg ); // --> NULL
var_dump( $$lvar); // --> NULL
}
// END //////////////////////////////////////////////////////////////
Regards,
A. Rico