2011-12-31 14 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

お手数ですが 戻り値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

関連する問題