#47400 [NEW]: Variable variables don't work with "global" inside a function

From: Date: Mon, 16 Feb 2009 04:20:27 +0000
Subject: #47400 [NEW]: Variable variables don't work with "global" inside a function
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-1870@lists.php.net to get a copy of this message
From: php at richardneill dot org Operating system: PHP version: Irrelevant PHP Bug Type: Documentation problem Bug description: Variable variables don't work with "global" inside a function Description: ------------ Note sure whether this is an actual bug, or an omission from the documentation. Anyway, it doesn't seem to work when we use "global" to bring a variable into scope within a function, iff that variable name is itself a variable variable. The example below is the shortest possible demonstration of the problem I can create (sorry it looks very contrived). Thanks for your help. Reproduce code: --------------- <? $fruit = "apple"; $lunch = "fruit"; $eat1 = $$lunch; echo "Tasty: $eat1\n"; // apple, as expected function nom ($meal) { //$meal contains the string 'lunch' $eat2=$$meal; //$eat2 should be the variable $lunch global $eat2; //...which we bring into scope using "global" echo "Tasty: $eat2\n"; //Should give "apple", but doesn't. } nom ('lunch'); ?> Expected result: ---------------- Tasty: apple Tasty: apple Actual result: -------------- Tasty: apple Tasty: -- Edit bug report at http://bugs.php.net/?id=47400&edit=1 -- Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=47400&r=trysnapshot52 Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=47400&r=trysnapshot53 Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=47400&r=trysnapshot60 Fixed in CVS: http://bugs.php.net/fix.php?id=47400&r=fixedcvs Fixed in CVS and need be documented: http://bugs.php.net/fix.php?id=47400&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=47400&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=47400&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=47400&r=needscript Try newer version: http://bugs.php.net/fix.php?id=47400&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=47400&r=support Expected behavior: http://bugs.php.net/fix.php?id=47400&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=47400&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=47400&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=47400&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=47400&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=47400&r=dst IIS Stability: http://bugs.php.net/fix.php?id=47400&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=47400&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=47400&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=47400&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=47400&r=mysqlcfg

« previous php.doc.bugs (#1870) next »