2011-12-31 2 views
0

내가 마술 방법 다음 코드는 메소드의 호출에 하나 개 이상의 인수가있는 경우를 제외하고 잘 작동 __call매직 방법 __call는 여러 인수

에 문제가 잘 작동하지 않습니다. 나는 (단지 $args 또는 implode(', ' $args)가 작동하지 않습니다) 좋은 결과없이 다른 솔루션을 시도했습니다 나는이처럼 쓰는 경우도 작동

public function __call($method, $args) { 
    if($this->methods[$method] != NULL) 
      return $this->objects[$this->methods[$method]]->$method($args[0]); 
    else trigger_error("Call undefined method " . $this->class . "::" . $method, E_USER_ERROR); 
} 

:

return $this->objects[$this->methods[$method]]->$method($args[0], $args[1], $args[3]); 

을하지만 당신은이를 볼 수 함수가 0에서 무한 인수까지 가질 수 있기 때문에 올바르지 않습니다.

스크립트에서 여러 인수를 수정하는 방법을 알고 있습니까?

답변

8
return call_user_func_array($this->objects[$this->methods[$method]]->$method, $args); 

http://php.net/call_user_func_array을 참조하십시오.

+2

도와 주셔서 감사합니다 return call_user_func_array (array ($ this-> objects [$ this-> methods [$ method]], $ args); 잘 작동합니다. D return call_user_func_array ($ this-> objects [$ this-> methods [$ method]] -> $ method, $ args); 작업하지 않음 – oscurodrago