What is the __call () Magic method?
__call is one of the magic methods that calls the __call method when a program calls a method that is not declared in the current class or that does not have permission to call it. The __call () method contains two parameters, the method name and the method parameter. Where the method parameter is in the form of an array.
Here's a simple example to help you understand:
<?phpheader ("Content-type:text/html;charset=utf-8"); class Sport{public function Run () {echo ' method exists directly calling me ';} function __call ($name, $arguments) {echo ' method does not exist call me '; Echo ' <br/> '; Echo ' method named: '. $name; Echo ' <br/> '; Echo ' parameter is:<pre> '; Var_dump ($arguments);}} $sport = new Sport (); $sport->run (); Echo ' <br/> '; $sport->football (' David Beckham ', 30);
We create a class that creates a run method and a magic Method __call () in the class. Next, we instantiate the object $sport call two methods, one is the run () method that exists in the class, and one is the football () method that does not exist. You can run the code to see the results.