#22518 [Com]: Accessing superglobal arrays in functions via variable variable names

From: Date: Mon, 03 Mar 2003 15:22:01 +0000
Subject: #22518 [Com]: Accessing superglobal arrays in functions via variable variable names
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-34671@lists.php.net to get a copy of this message
ID: 22518 Comment by: daniel dot gorski at develnet dot org Reported By: rabus at users dot sourceforge dot net Status: Open Bug Type: Scripting Engine problem Operating System: Windows NT PHP Version: 5CVS-2003-03-03 (dev) New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#34671) next »