__call 當要調用的方法不存在或權限不足時,會自動調用__call 方法。
__callStatic 當調用的靜態(tài)方法不存在或權限不足時,會自動調用__callStatic方法。
__call($funcname, $arguments)
__callStatic($funcname, $arguments)
參數說明:
$funcname String 調用的方法名稱。
$arguments Array 調用方法時所帶的參數。
class Test{ public function __call($fun,$arg) { echo "當調用的方法不存在或者沒有權限時, 就開始調用__call了<br/>"; echo "方法名: $fun<br/>"; var_dump($arg); } public static function __callStatic($fun,$arg) { echo "當調用的靜態(tài)方法不存在或者沒有權限時, 就開始調用__callStatic了<br/>"; echo "調用方法名: $fun<br/>"; var_dump($arg); } } $test = new Test(); $test -> sing('莊子',18); //Test類中沒有 sing方法 , 自動調用 __call方法 Test::zhuangzi('carl','男'); //Test類中沒有 zhuangzi 靜態(tài)方法 自動調用 __callStatic方法