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.

Was it helpful?

Solution

I think you want to use magic method __get: http://www.php.net/manual/en/language.oop5.overloading.php#object.get

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top