The difference between PHP magic variable __method__,__function__

Source: Internet
Author: User

The method name of the __method__ class (PHP 5.0.0 new addition). Returns the name of the method when it is defined (case-sensitive).
__function__ function name (PHP 4.3.0 new addition). From PHP 5 This constant returns the name (case-sensitive) when the function is defined. In PHP 4, this value is always in lowercase letters.
The document interpretation is the name of the return function (method). The difference is:
__FUNCTION__ is just the name of the return method;
__METHOD__ returns the name of the class and the name of the method.

1<?PHP2             classtest{3                  Public functiondoit () {4                     Echo __function__;5                 }6                  Public functionDoitagain () {7                     Echo __method__;8                 }9             }Ten             $obj=NewTest (); One             $obj-doit (); A             Echo' <br> '; -             $obj-Doitagain (); -?>

The output is:

Doit
Test::d Oitagain

The difference between PHP magic variable __method__,__function__

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.