RE: [PHP-GENERAL] Object reference...

From: Date: Sun, 21 May 2000 23:23:09 +0000
Subject: RE: [PHP-GENERAL] Object reference...
Groups: php.general php.general 
Request: Send a blank email to php-general+get-262@lists.php.net to get a copy of this message
>On Sun, 21 May 2000, David Tiselius wrote: >> I can't get this to work inside a class: >> >> $object->foo = "something"; >> $bar = "foo"; >> print $object->$bar; >> >> I thought I'd get something out... >> Outside a class the above works. Everything concerned is declared within the >> same function in the class so i shouldn't have to refer to my object with >> $this->object, right? (anyway, I've tried it and I still get nothing). >> print $object->foo; works so the object's not empty. >Actually, when you're inside a class method you do need to use $this-> to >refer to class variables. If you don't, it's assumed you're referring to >a variable local to that method. [snip] and that's what they are - just local to the method, both the object and the variables. print $object->foo; prints "something" and print $bar; prints "foo". So all the variables are actually "in place". However print $object->$bar; doesn't print anything.

« previous php.general (#262) next »