note 49466 deleted from language.variables.variable by danbrown
| From: | danbrown@php.net | Date: | Wed, 24 Jun 2009 16:15:05 +0000 |
| Subject: | note 49466 deleted from language.variables.variable by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-157374@lists.php.net to get a copy of this message | ||
Note Submitter:
----
in response to "pear at inkas dot it"
${$_SESSION['var_name']} does work. What doesn''t work is something like this:
<?php
// consider file has been called with ?var=val
function test() {
$val = '_GET';
var_dump($$a);
echo "\n";
var_dump(${$_GET['var']});
}
test();
?>
will output
NULL
string(4) "_GET"
the use of $$a inside a function or method will not reference the superglobal ever, but instead look
for a local variable $_GET, which will never exist, even if you try to create one by doing something
like "$_GET = array();" inside the function. setting "global $_GET" inside the
function won't work also. You simply can't create a reference to a superglobal inside a
function or method by trying to access it via a variable variable.