The __call () method is used to monitor incorrect method calls.
__call () (Method overloading)
To avoid errors when the calling method does not exist, you can use the __call () method to avoid it. The method will be called automatically when the calling method does not exist, and the program will continue to execute.
Grammar:
function __call (string $function _name, array $arguments) { ...}
The method has two parameters, the first parameter $function _name automatically receives the method name that does not exist, and the second $args receives multiple arguments of the non-existent method in the form of an array.
Add in class:
function __call ($function _name, $args) { echo "functions you call: $function _name (Parameters: <br/>"; Var_dump ($args); echo ") does not exist! ";}
When calling a non-existent method (such as the Test () method):
$p 1=new person (); $p 1->test (2, "test");
The results of the output are as follows:
The function you are calling: Test (parameter: Array (2) { [0]=>int (2) [1]=>string (4) "test"}) does not exist!
PHP overloaded Method __call ()