What is the __call() magic method?
__call is one of the magic methods. When the program calls a method that is not declared or has no permission to call in the current class, the __call method will be called. The __call() method contains two parameters, namely method name and method parameters. Among them, method parameters exist in the form of arrays.
Let’s give a simple example to help everyone understand:
'; echo '方法名为:'. $name; echo '
'; echo '参数为:'; var_dump($arguments); } } $sport = new Sport(); $sport ->run(); echo '
'; $sport ->football('贝克汉姆',30);Copy after login
We create a class and create a run method and magic method __call() in the class. Next, we instantiate the object $sport and call two methods, one is the run() method that exists in the class, and the other is the football() method that does not exist. You can run the code to see the results.
The above is the detailed content of Detailed explanation of magic method __call() instance (php advanced object-oriented tutorial). For more information, please follow other related articles on the PHP Chinese website!