Php overload (2) _ PHP Tutorial

Source: Internet
Author: User
Php overload (2 ). Php overload (2) next to the overload mentioned last time. let's take a look at the overload in php and the method overload. if there is a definition of the overload, refer to: Reload in php (1) thank you for this article. 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.

Rewrite overload (2) next to the overload mentioned last time. let's take a look at the overloading of methods in php. if there is a definition of overloading, refer to: Reload in php (1, thank you. as...

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.