note 11623 modified in Variable variables by jeroen
| From: | jeroen@php.net | Date: | Thu, 24 May 2001 00:25:07 +0000 |
| Subject: | note 11623 modified in Variable variables by jeroen | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-14238@lists.php.net to get a copy of this message | ||
[Ed: Scoping is identical to 'normal' variables.]
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).
function test() {
do {
$varname = 'text';
$$varname = 'testing 1,2,3';
while(0);
print $text;
}
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/variable-variables.php