note 31857 modified in language.variables.variable by danbrown

From: Date: Wed, 24 Jun 2009 16:57:54 +0000
Subject: note 31857 modified in language.variables.variable by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-157407@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: <?php 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 --was-- 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://php.net/manual/en/language.variables.variable.php

« previous php.notes (#157407) next »