Php overload (2)
Next, let's take a look at the reloads mentioned last time in php and the methods. If you have a definition of reloads, refer to: reloads in php (1). Thank you. as a beginner, Do not spray:
There are two methods.
_ Call: This magic method is automatically executed when you call a method for an inaccessible object! (Object call)
Two typical processing methods:
1. Give a friendly prompt!
2. Perform the default operation!
_ Callstatic: This magic method is automatically executed when an inaccessible static method is called!
Code details:
Class Student {
Public $ name = 'php ';
Public $ age = 10;
Public function sayName (){
Return $ this-> name;
}
/**
* @ Param $ method_name string method name
* @ Param $ parameters included in the method_arguments array call
*/
Public function _ call ($ method_name, $ method_arguments ){
Echo'
Sorry, the method you called does not exist !, You should call the (***) method! ';
$ This-> defaultAction (); // executes the default method and can be used for redirection to implement redirect.
}
Public function defaultAction (){
Echo'
Here is the default action! ';
}
Public static function _ callStatic ($ m_name, $ m_args ){
Echo 'here is a static method overload! ';
}
}
Student: sayCounter ();
The above is an example for reference during the learning process. Let's take a look at it. If you have any questions, we can discuss it.