2013-04-01 70 views
0
 class My_class { 

     public function __call($name, $arguments) { 

      echo "Called method ".$name.", arguments count is: ".count($arguments); 

     } 


    } 

    $obj = new My_class(); 

    $arr = array(1,2,3); 

    $obj->blabla($arr); 

結果是:Called method blabla, arguments count is: 1誤解在PHP的魔術方法__call()

問:爲什麼參數計數爲1,而不是3?我錯在哪裏?

+3

因爲你正在傳遞一個參數 - 數組。如果你想要三個 - 使用'$ obj-> blabla(1,2,3)' – J0HN

+0

@ J0HN來調用它,謝謝,(但是我需要更多的字符來發布這個) – RIKI

回答

0

該腳本不計數數組中的項目,只有參數號,唯一的參數是$ arr。

則需要使用數項:

count($arr);