__call only two parameters? Why does this code pass several parameters?
I see someone say that. __call the first parameter, $m, is the method you want to call test. I can't understand that. The first parameter is not a 1?
x; }}$foo = new Caller();$a = $foo->test(1, "2", 3.4, true);var_dump($a);?>
Reply content:
__call only two parameters? Why does this code pass several parameters?
I see someone say that. __call the first parameter, $m, is the method you want to call test. I can't understand that. The first parameter is not a 1?
x; }}$foo = new Caller();$a = $foo->test(1, "2", 3.4, true);var_dump($a);?>
__call
is called when an undefined method is called.
That is, if your test
method is undefined, the test
method name is passed in as __call
the first argument, and test
the parameter is passed in as __call
the second parameter in the array.
So when you call $foo->test(1, "2", 3.4, true)
, it's actually the equivalent of a call $foo->__call('test', array(1, "2", 3.4, true))
.
The __call method is triggered when a method of the class is called, such as:
"后面的字符串,$parameters是通过这个方法传过来的参数 }}$google = new google();$keyword = 'VR';$google->search($keyword);//当调用当前对象不存在的方法时,会转向__call$google->operate();
With __call, you can do some encapsulation to invoke other objects and methods.
Attached official reference: PHP Magic method
The first parameter is the function name of the non-existent method that you call, and the second is a pair of arguments that you call a non-existent method simultaneous