0

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.

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
aya
  • 1,597
  • 4
  • 29
  • 59

1 Answers1

1

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

Danil Speransky
  • 29,891
  • 5
  • 68
  • 79