I think you want to use magic method __get
: http://www.php.net/manual/en/language.oop5.overloading.php#object.get
access to member of object in php with value of parameter? [closed]
-
10-03-2022 - |
Question
i want return on of properties of myobject
like this code :
class myobject{
var $foo = 1;
var $bar = 2;
function getProperty($Field) {
return $this->$Field;// this line have error
}
}
$object = new myobject();
i call method like this
$object->getProperty("foo");
but line
return $this->$Field;
have an error.
Solution
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow