note 62481 deleted from language.variables.variable by danbrown
| From: | danbrown@php.net | Date: | Wed, 24 Jun 2009 16:53:29 +0000 |
| Subject: | note 62481 deleted from language.variables.variable by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-157396@lists.php.net to get a copy of this message | ||
Note Submitter: bclark <at> digitalbc <dot> net
----
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