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 (); ?>