PHP Magic Variable __method__,__function__ difference, functionmethod_php tutorial

Source: Internet
Author: User

PHP Magic Variable __method__,__function__ difference, Functionmethod


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 
   PHP 2             class  test{  3public                 function  doit () {  4                     echo__function__; 5                 }  6public                 function  doitagain () {  7                     echo__method__; 8                 }  9            }             $objnew  Test ();  One             $obj-doit ();  a             Echo '
'; - $obj-Doitagain (); ?>

The output is:

Doit
Test::d Oitagain


The specific role of the PHP magic variable

The current line number in the __line__ file.

The full path and file name of the __file__ file. If used in the included file, returns the file name that is included. From PHP 4.0.2, __file__ always contains an absolute path (if it is a symbolic connection, the resolved absolute path), and the previous version sometimes contains a relative path.

The directory where the __dir__ file resides. If used in the included file, returns the directory where the included files are located. It is equivalent to DirName (__file__). Unless it is a root directory, the name in the directory does not include the trailing slash. (New in PHP 5.3.0) =

__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 name of the __class__ class (PHP 4.3.0 new addition). From PHP 5 This constant returns the name of the class when it is defined (case-sensitive). In PHP 4, this value is always in lowercase letters.

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).

__NAMESPACE__ the name of the current namespace (case sensitive). This constant is defined at compile time.

PHP Magic variable is what the explanation, do not copy and then to paste

Magic variables are those that have different values depending on the environment.
Like what
__file__
is a typical magic variable, when it appears in the a.php file, its value is the specific path of a.php, appearing in the b.php file is b.php specific path
Some of the other magic variables are __function__, __class__.
In short, the values of these variables are often not fixed, changed to change, very magical, like magic, it is called magic variable

http://www.bkjia.com/PHPjc/886485.html www.bkjia.com true http://www.bkjia.com/PHPjc/886485.html techarticle PHP Magic variable __method__,__function__ difference, Functionmethod __method__ class method name (PHP 5.0.0 new Plus). Returns the name of the method when it is defined (case-sensitive). __f ...

  • 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.