2013-07-29 4 views
-1

PHP에서 oop를 배우기 시작 했으므로 여러 가지 인수를 허용하는 내 메서드가 무엇인지 잘못 알고 싶습니다.PHP에서 다중 인수가있는 함수

class Database 
{  
    public function __call($method, $args) 
    { 
     if($method == 'insertData') 
     { 
      if(count($args) == 2) 
      { 
       return call_user_func_array(($this, 'insertData1'), $args)); //unexpected token ',' after $this 
      } 
      else if(count($args) == 3) 
      { 
       return call_user_func_array(($this, 'insertData2'), $args)); 
      } 
     } 
    } 

    public function insertData1($table, $field1) 
    { 

    } 

    public function insertData2($table, $field1, $field2) 
    { 

    } 
} 
+0

구문 오류를 수정하는 것이 쉽기 때문에 주제를 벗어난 것 같습니다. '($ this, 'insertData1')'는 [유효한 콜백 표기법]이 아닙니다 (http://de1.php.net/manual/en/language.types.callable.php). – Gordon

+0

액세스 할 수없는 메서드에서만 호출이 발생하지 않으므로 두 메서드 모두 public이므로이 경우 호출되지 않습니다. – Aeveus

+0

@JackieXu OP는 분명히'insertData' 만 호출합니다. – Gordon

답변

1

당신은 당신의 메서드 호출에서 배열을 누락 :

call_user_func_array(array($this, 'insertData1'), $args)); 

대신 :

call_user_func_array(array($this, 'insertData1'), $args); 
1

call_user_func_array의 첫 번째 인수가 호출이나, 귀하의 경우, 배열해야합니다 :

call_user_func_array(($this, 'insertData1'), $args));