Bug #17017 Updated: Variable superglobal variable not recognised within function and method

From: Date: Sun, 05 May 2002 17:00:20 +0000
Subject: Bug #17017 Updated: Variable superglobal variable not recognised within function and method
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-6961@lists.php.net to get a copy of this message
ID: 17017 Updated by: mfischer@php.net Reported By: lennart.mulder@gmx.net -Status: Open +Status: Duplicate Bug Type: Variables related Operating System: Linux PHP Version: 4.2.0 New Comment: Known limitation. I don't know yet if this has been documented already, there's another report about this issue though. Marking as duplicate for now. Previous Comments: ------------------------------------------------------------------------ [2002-05-05 12:58:27] lennart.mulder@gmx.net Hello :-) The definition of a variable variable as superglobal works fine when put in the main coding (i.e. not within a function or method). Example: <?php $aVariable = 'GET'; echo ${"_{$aVariable}"}; ?> The system output is: Array In the next example however, where the same code is put into a function, the resulting output is a error message instead: <?php function aFunction() { $aVariable = 'GET'; echo ${"_{$aVariable}"}; } aFunction(); ?> The system output is: Notice: Undefined variable: _GET in Bestand.php on line 6. Also when $_GET has been defined as global (which should not be necessary) this malfunction remains. Suggested intermediate solution: <?php function aFunction() { $aVariable = 'GET'; echo $GLOBALS["_{$aVariable}"]; } aFunction(); ?> ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=17017&edit=1

« previous php.bugs (#6961) next »