Overload in PHP (ii)

Source: Internet
Author: User

Then the last said overload, we understand the next overload in PHP, the method of overloading, if there is a pipe overload definition, reference: PHP overload (i) This article, thank you. As a beginner, Daniel, don't spray:

Basically, two methods.

__call, the Magic method is automatically executed when a method is invoked on an object that is not accessible! (Object invocation)

Typical two ways of handling:

1, give a friendly hint!

2, perform the default action!

__callstatic, the Magic method is automatically executed when an inaccessible static method is invoked!

Detailed code:

Class Student {
Public $name = ' php ';
Public $age = 10;

Public Function Sayname () {
return $this->name;
}

/**
* @param $method _name String method name
* @param $method parameters to be carried when _arguments array calls
*/
Public Function __call ($method _name, $method _arguments) {
Echo '
Sorry, you call the method does not exist!, you should call (* * *) Method! ';

$this->defaultaction ();//Execute the default method, you can do the jump switch, realize redirect


}

Public Function DefaultAction () {
Echo '
This is the default action! ';
}

public static function __callstatic ($m _name, $m _args) {
Echo ' Here is the static method overload! ';
}
}
Student::saycounter ();
The above is the study time reference example, under ... If there are questions, we can discuss



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.