[Materials] use of _ call in PHP

Source: Internet
Author: User
Use of _ call in PHP

Official documents: http://cn2.php.net/__call

Public mixed _ call (string $ name, array $ arguments)
Public static mixed _ callstatic (string $ name, array $ arguments)
When an inaccessible method (such as undefined or invisible) is called, __call () is called.

When an inaccessible method (such as undefined or invisible) is called in a static method, __callstatic () is called.

The $ name parameter is the name of the method to be called. The $ arguments parameter is an array containing the parameter to be passed to the method $ name.

Demo 1
<? PHP  Class  Personwriter {  Function Writename (person $ P  ){  Print   $ P -> Getname (). "\ n" ;}  Function Writeage (person $ P  ){  Print   $ P -> Getage (). "\ n" ;}}  Class  Person {  Private   $ Writer ;  Function _ Construct (personwriter $ Writer  ){  $ This -> Writer = $ Writer  ;}  Function _ Call ( $ Method , $ ARGs  ){  If ( Method_exists ( $ This -> Writer,$ Method  )){  Return   $ This -> Writer-> $ Method ( $ This  );}}  Function Getname (){ Return "Bob" ;}  Function Getage (){ Return 44 ;}}  $ Person =New Person ( New  Personwriter ());  $ Person -> Writename ();  $ Person -> Writeage (); ?>

 

 

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.