Getting a variable from an object with a string in PHP
Posted
by Josh K
on Stack Overflow
See other posts from Stack Overflow
or by Josh K
Published on 2010-06-10T19:34:56Z
Indexed on
2010/06/10
20:12 UTC
Read the original article
Hit count: 203
I have a Persons
object. It has a variable name
accessible by saying
$p = new Person('John');
echo $p->name;
Now I have a string.
$name = 'name';
I need to get $p->name
using $p
and $name
. Something like
echo $p->[$name];
© Stack Overflow or respective owner