<?phpdeclare(strict_types=1);//开启强类型模式class Person{ public function say(){ echo "Hello world"; echo "\r\n"; }}(new Person())->say();//调用类中存在的方法(new Person())->eat(‘food‘);//调用类中不存在的方法
调用类中不存在的方法PHP Fatal error: Uncaught Error: Call to undefined method Person::eat() in /home/zrj/www/zhangrenjie_test/test/36.php:26Stack trace:#0 {main} thrown in /home/zrj/www/zhangrenjie_test/test/36.php on line 26
class Person{ public function say() { echo "Hello world"; echo "\r\n"; } // 在对象中调用一个不可访问方法时,__call() 会被调用。 public function __call($functionName, $arguments) { echo "您调用了类中不存在的方法:" . $functionName . "\r\n"; echo "接受的参数为:" . print_r($arguments, true); }}(new Person())->say();(new Person())->eat(‘food‘, ‘chicken‘, ‘bull‘);
Hello world
您调用了类中不存在的方法:eat
接受的参数为:Array
(
[0] => food
[1] => cocal
[2] => bull
)
本文出自 “我的PHP之路” 博客,请务必保留此出处http://phpme.blog.51cto.com/663593/1982125
回顾php魔术方法call
原文地址:http://phpme.blog.51cto.com/663593/1982125