note 11623 added to Variable variables
| From: | kevin at php2 dot chek dot com | Date: | Wed, 28 Feb 2001 02:46:27 +0000 |
| Subject: | note 11623 added to Variable variables | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-11647@lists.php.net to get a copy of this message | ||
<p>This manual never seems to mention how scoping applies to variable variables. From what I
can tell, variable variables are scoped to the nearest enclosing function (not to the nearest
enclosing block, thankfully).</p>
function test() {
do {
$varname = 'text';
$$varname = 'testing 1,2,3';
while(0);
print $text;
}<br>
<BR>
will give you 'testing 1,2,3'. This may be confusing to people who are used to stricter
scoping rules.
http://www.php.net/manual/en/language.variables.variable.php