#22518 [Bgs]: Accessing superglobal arrays in functions via variable variable names
| From: | rabus at users dot sourceforge dot net | Date: | Tue, 04 Mar 2003 10:57:11 +0000 |
| Subject: | #22518 [Bgs]: Accessing superglobal arrays in functions via variable variable names | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-34746@lists.php.net to get a copy of this message | ||
ID: 22518
User updated by: rabus at users dot sourceforge dot net
Reported By: rabus at users dot sourceforge dot net
Status: Bogus
Bug Type: Scripting Engine problem
Operating System: Windows NT
PHP Version: 5CVS-2003-03-03 (dev)
New Comment:
I am sorry for this bogus report.
Since German is my mother tounge, I read the German edition of your
manual. Unfortunately, the note you mentioned is missing there.
From now on, I'll read the English one, only, since the German one
appears a little out-of-date to me.
Previous Comments:
------------------------------------------------------------------------
[2003-03-03 20:14:11] sniper@php.net
RTFM:
http://www.php.net/manual/en/language.variables.predefined.php#language.variables.predefined
"Variable variables: Superglobals cannot be used as variable
variables."
------------------------------------------------------------------------
[2003-03-03 09:22:00] daniel dot gorski at develnet dot org
Similar malfunction here:
<?php
error_reporting(E_ALL);
print_r($_SERVER);
print_r($_ENV);
?>
PHP Notice: Undefined variable: _SERVER in
/var/webservers/cowiki/htdocs/test.php on line 6
PHP Notice: Undefined variable: _ENV in
/var/webservers/cowiki/htdocs/test.php on line 7
Todays CVS, build as CGI on RH6.2
regards dtg
------------------------------------------------------------------------
[2003-03-03 08:06:46] rabus at users dot sourceforge dot net
Please try the following script:
<?php
function foo() {
echo $_SERVER;
}
foo();
?>
This script returns "Array". This is the expected behavior.
Now, try this one:
<?php
function foo() {
$bar = '_SERVER';
echo $$bar;
}
foo();
?>
This time, an error is returned:
Notice: Undefined variable: _SERVER on line 4
This is nonsense, of course: As we see in the example above, the
variable should be defined!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=22518&edit=1