note 49466 added to language.variables.variable
| From: | php-general at lists dot php dot net | Date: | Sat, 29 Jan 2005 00:20:43 +0000 |
| Subject: | note 49466 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84141@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/language.variables.variable.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49466
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49466&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49466&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49466&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49466&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49466&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49466&report=yes
Search -- http://master.php.net/manage/user-notes.php