PHP overloaded Method __call ()

Source: Internet
Author: User

The __call () method is used to monitor incorrect method calls.

__call () (Method overloading)

To avoid errors when the calling method does not exist, you can use the __call () method to avoid it. The method will be called automatically when the calling method does not exist, and the program will continue to execute.

Grammar:

function __call (string $function _name, array $arguments) {    ...}

The method has two parameters, the first parameter $function _name automatically receives the method name that does not exist, and the second $args receives multiple arguments of the non-existent method in the form of an array.

Add in class:

function __call ($function _name, $args) {    echo "functions you call: $function _name (Parameters: <br/>";    Var_dump ($args);    echo ") does not exist! ";}

When calling a non-existent method (such as the Test () method):

$p 1=new person (); $p 1->test (2, "test");

The results of the output are as follows:

The function you are calling: Test (parameter: Array (2) {    [0]=>int (2)    [1]=>string (4) "test"}) does not exist!

PHP overloaded Method __call ()

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.