2013-04-01 75 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);