note 62481 added to language.variables.variable
| From: | bclark<at>digitalbc" net | Date: | Wed, 01 Mar 2006 16:18:40 +0000 |
| Subject: | note 62481 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-104639@lists.php.net to get a copy of this message | ||
using variable variables to loop through class methods or properties, not all that common, but
useful if you need it.
class foo {
public $thing1 = 'a';
public $thing2 = 'b';
public $thing3 = 'c';
public function getThing1() {
return $this->thing1;
}
public function getThing2() {
return $this->thing3;
}
public function getThing3() {
return $this->thing3;
}
}
$obj = new foo();
for($i=0;$i <=3 ;$i++) {
print $obj->{getThing.$i}."\n";
}
output is
a
b
c
----
Server IP: 66.163.161.117
Probable Submitter: 128.192.88.205
----
X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER
autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/language.variables.variable.php
Edit -- http://master.php.net/note/edit/62481
Del: integrated -- http://master.php.net/note/delete/62481/integrated
Del: useless -- http://master.php.net/note/delete/62481/useless
Del: bad code -- http://master.php.net/note/delete/62481/bad+code
Del: spam -- http://master.php.net/note/delete/62481/spam
Del: non-english -- http://master.php.net/note/delete/62481/non-english
Del: in docs -- http://master.php.net/note/delete/62481/in+docs
Del: other reasons-- http://master.php.net/note/delete/62481
Reject -- http://master.php.net/note/reject/62481
Search -- http://master.php.net/manage/user-notes.php