Bug #15871 Updated: variable variables need { } to work with classes
| From: | rasmus@php.net | Date: | Tue, 05 Mar 2002 13:34:19 +0000 |
| Subject: | Bug #15871 Updated: variable variables need { } to work with classes | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-1679@lists.php.net to get a copy of this message | ||
ID: 15871
Updated by: rasmus@php.net
Reported By: greg@mtechsolutions.ca
Status: Bogus
Bug Type: Variables related
Operating System: linux
PHP Version: 4.1.2
New Comment:
Just to give you a better answer here. Consider $$a->b
Does this mean the the class name $$a with the property b or the
variable property $a->b? See the vagueness here? It could be
interpreted as either ${$a->b} or {$$a}->b. That's why the {}'s are
needed to resolve this ambiguity.
Previous Comments:
------------------------------------------------------------------------
[2002-03-05 07:22:00] derick@php.net
Actually this isn't a bug, but just 'how things work'.
regards,
Derick
------------------------------------------------------------------------
[2002-03-05 07:13:34] greg@mtechsolutions.ca
When using a variable variable in a class, $$this->varname does not
work, ${$this->varname} must be used.
Here is a simple script to show this in action. Put the {} in and it
will work:
<?
$id = "yes";
class testClass {
var $varname;
function testClass($varname) {
$this->varname = $varname;
}
function foo() {
global $$this->varname;
echo "$".$this->varname." is ".$$this->varname;
}
}
$test = new testClass("id");
$test->foo();
?>
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=15871&edit=1