ID: 25692 Updated by: [EMAIL PROTECTED] Reported By: declan at context dot ie -Status: Open +Status: Bogus -Bug Type: Arrays related +Bug Type: *General Issues Operating System: linux PHP Version: Irrelevant New Comment:
Try setting error_reporting to E_ALL and you'll find out why it doesn't work. Previous Comments: ------------------------------------------------------------------------ [2003-09-29 10:50:13] declan at context dot ie Description: ------------ If you pass a variable name to a function and then try to dereference that variable name for use in a global statement, then the global statement fails. I believe the problem lies in the way that global is implemented. If I have the following: $ary[foo]="bar"; function use_global($varname) { global $$varname; echo "$varname is set to ". $$varname; } use_global ("ary[foo]"); then I think that the global line is being re-written to be equivalent to something like: $_use_global_varname=&$GLOBALS["ary[foo]"]; whereas, AFAICS, it should be: $_use_global_varname=&$GLOBALS["ary"]["foo"]; I want to be able to use this construct without having to know whether the incoming variable is a plain variable or an array element. Reproduce code: --------------- <?php // -*-php-*- function use_global ($formvar) { $ref=&$GLOBALS[$formvar]; echo "formvar: $formvar = " . $$ref; }; $global=array (); $global["foo"]=1; $global["bar"]=2; $global["baz"]=3; echo "global[bar]=$global[bar]\n"; use_global("global[bar]"); ?> Expected result: ---------------- If things worked correctly, the output should be: global[bar]=2 formvar: global[bar] =2 Actual result: -------------- global[bar]=2 formvar: global[bar] = ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=25692&edit=1