Pregunta

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.

¿Fue útil?

Solución

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

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top