<?phpdeclare (Strict_types=1);//Open strong Type mode class person{public function Say () {echo "Hello world"; echo "\ r \ n"; }} (new Person ())->say ();//Call the method that exists in the class (New person ())->eat (' food ');//Call a method that does not exist in the class
Methods that do not exist in the calling class 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 () is called when an inaccessible method is called in the object. Public Function __call ($functionName, $arguments) {echo "You called a method that does not exist in the class:". $functionName. "\ r \ n"; echo "Accepts parameters as:". Print_r ($arguments, true); }} (new Person ())->say ();(the New Person ())->eat (' food ', ' chicken ', ' Bull ');
Hello World
You have called a method that does not exist in the class: Eat
The parameters accepted are: Array
(
[0] = food
[1] = cocal
[2] = Bull
)
This article is from the "My PHP path" blog, so be sure to keep this source http://phpme.blog.51cto.com/663593/1982125
Review PHP Magic method call