2016-11-24 8 views
0

내가 다음과 같습니다 클래스가 있습니다존재하지 않는 메소드를 호출 할 때 __call 대신 __get이 호출되는 이유는 무엇입니까?

class MyClass 
{ 
    public __get($prop) 
    { 
     $method = 'get' . ucfirst($prop); 
     if (method_exists($this, $metodo)) 
      return $this->$metodo(); 
     if (property_exists($this, $prop)) 
      return $this->$prop; 

     throw new Exception("Nonexisting property $prop"); 
    } 

    public function __call($method, $args) 
    { 
     $prop = strtr($method, 'add', ''); 
     $prop = lcfirst($prop); 

     if (is_array($this->$prop)) 
      array_push($this->$prop, $args[0]); 
    } 
} 

하지만 $obj->addTags('test');을 할 경우는 __get를 호출을, 마녀가 나에게 메시지와 함께 예외 제공 : "존재하지 않는 속성 addTags"

을 내가 뭘해야 내 __call 대신 내 __get을 호출해야합니까?

미리 감사드립니다.

답변

0

방금 ​​str_replace 대신 strtr을 교체했습니다. 올바른 속성 이름을 얻지 못하고 지금 작동합니다.

스택 오버플로가 허용되는 즉시 답변으로 표시해 드리겠습니다.

: -D