Method overloading: The __call () method is called automatically when a method that does not exist or has insufficient permissions is called
Public Function __call ($name, $args) {}: Invoke method with Object
public static function __callstatic ($name, $args) {}: Calling a static method with a class
$name: Called Method name
$args: An array of parameter lists for the called method
<?PHP//php Method Overloading classperson{//Method Private functionTest () {Echo __method__; } protected Static functiontest1 () {Echo __method__; } //Add Magic Method//There are two parameters: the first is the method name, the second is the parameter array Public function__call ($name,$args){ //Var_dump ($name);//Method name//var_dump ($args);//parameter array//define Allow access to list $allow=Array(' Test '); if(In_array($name,$allow)) $this-$name();//Variable Method Else return false; } //add access to a static method Public Static function__callstatic ($name,$args){ $allow=Array(' Test1 '); if(In_array($name,$allow)) self::$name();//Variable Method Else return false; } } Echo' <pre> '; //instantiation of $person=NewPerson ; //Access Private method//No Magic method before//$person->test (); Error//person::test1 (); Error $person->test ();//with the __call magic method, and allow access to Var_dump($person->test2 ());//false Person:: Test1 ();
PHP--Magic Method call Method: __call (), __callstatic ()