This article mainly shares with you how to use __call() and __callStatic() in PHP. I hope it can help you. I won’t explain too much about the use of these two methods. Through the example code and results, everyone can understand the functions of the two more clearly.
1.__call() method. When calling a method that is not declared in the class, you can call the __call() method instead of declaring a method. Accepts method name and array as parameters.
Code example:
'; echo '还传了一个参数
'; echo print_r($arg),'
'; } $list=new test(); $list->say(1,2,3); ?>
Execution result:
You want to call my non-existent method say method
also passed it One parameter
Array ([0] => 1 [1] => 2 [2] => 3 )
'; echo '还传了一个参数
'; echo print_r($arg),'
'; } } test::cry('痛哭','鬼哭','号哭'); ?>
You want to call my non-existent cry static method
Also passed a parameter
Array ([0] => Cry[1] => Ghost cry[2] => Cry)
How to use the __call() method in php and overloading example analysis
php magic function __call() usage example analysis_PHP tutorial
Detailed explanation of php's magic methods __get(), __set(), __call(), __callStatic() and static usage
The above is the detailed content of How to use __call() and __callStatic() in PHP. For more information, please follow other related articles on the PHP Chinese website!