문제

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.

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top