#47400 [Opn]: Variable variables don't work with "global" inside a function
| From: | preinheimer@php.net | Date: | Mon, 16 Feb 2009 04:31:02 +0000 |
| Subject: | #47400 [Opn]: Variable variables don't work with "global" inside a function | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-1872@lists.php.net to get a copy of this message | ||
ID: 47400
Updated by: preinheimer@php.net
Reported By: php at richardneill dot org
Status: Open
Bug Type: Documentation problem
PHP Version: Irrelevant
New Comment:
also: http://www.php.net/manual/en/language.variables.variable.php
Where could we have put this information to make it easier for you to
find? (so as to help other developers in the future)
Previous Comments:
------------------------------------------------------------------------
[2009-02-16 04:24:59] preinheimer@php.net
Does the third comment on this page address your concerns?
http://www.php.net/manual/en/language.variables.superglobals.php
------------------------------------------------------------------------
[2009-02-16 04:20:27] php at richardneill dot org
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 this bug report at http://bugs.php.net/?id=47400&edit=1