PHP魔术方法__call()篇

当我们调用类中的方法时,如果方法不存在的话。__call会是运行,从而使错误不显示出来

 1 header('Content-type:text/html;charset="utf-8"');
 2 class Computer{
 3     public function _run(){
 4         echo '我正在运行中';
 5     }
 6     /*__call方法要求参数必须是两个*/
 7     public function __call($_methodName,$arrlist){
 8         echo $_methodName.'()方法不存在';    
 9         print_r($arrlist);    
10     }
11 }
12 //采用call()方法屏蔽不存在的方法
13  
14 $computer = new Computer();
15 /*go会传给__call方法的$_methodName参数,
16  *go里面的参数会传给$arrlist作为数组中的参数 
17  *
18  */
19 $computer->go(3,'长了是');
原文地址:https://www.cnblogs.com/changshaoshuai/p/3288337.html