Magic _ call () example (php object oriented advanced tutorial)

Source: Internet
Author: User
What is the _ call () magic method? _ Call is one of the magic methods. when the program calls a method that is not declared in the current class or has no permission to call, it will call the _ call method. The _ call () method contains two parameters: method name and method parameter. The method parameters exist in arrays. The following is a simple example for your understanding: What is the _ call () magic method?

_ Call is one of the magic methods. when the program calls a method that is not declared in the current class or has no permission to call, it will call the _ call method. The _ call () method contains two parameters: method name and method parameter. The method parameters exist in arrays.

The following is a simple example for your understanding:

 '; Echo' method name: '. $ name; echo'
The '; echo' parameter is:
'; Var_dump ($ arguments) ;}}$ sport = new Sport (); $ sport-> run (); echo'
'; $ Sport-> football ('Beckham', 30 );

We create a class and create a run method and magic method _ call () in the class (). Next, we instantiate the object $ sport to call two methods, one is the run () method in the class, and the other is the football () method that does not exist. You can run the code to view the results.

The above is the details of the magic method _ call () instance (php object oriented advanced tutorial). For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.