note 31857 added to language.variables.variable
| From: | sir_hmba at rack1 dot php dot net | Date: | Tue, 06 May 2003 20:08:48 +0000 |
| Subject: | note 31857 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-47597@lists.php.net to get a copy of this message | ||
This is somewhat redundant, but I didn't see an example that combined dynamic reference of
*both* object and attribute names.
Here's the code:
//----------------------------------------
class foo
{
var $bar;
var $baz;
function foo()
{
$this->bar = 3;
$this->baz = 6;
}
}
$f = new foo();
echo "f->bar=$f->bar f->baz=$f->baz\n";
$obj = 'f';
$attr = 'bar';
$val = $$obj->{$attr};
echo "obj=$obj attr=$attr val=$val\n";
//----------------------------------------
And here's the output:
f->bar=3 f->baz=6
$obj=f $attr=bar $val=3
--
http://www.php.net/manual/en/language.variables.variable.php
http://master.php.net/manage/user-notes.php?action=edit+31857
http://master.php.net/manage/user-notes.php?action=delete+31857
http://master.php.net/manage/user-notes.php?action=reject+31857