PHP magic constant _ METHOD _ introduction, constant _ method _ PHP Tutorial

Source: Internet
Author: User
PHP magic constant _ METHOD _ introduction, constant _ method _. Description of the magic constant _ METHOD _ in PHP. the constant _ method ___ METHOD _ is the magic constant added after PHP5, indicating the name of the quasi-grammar. A magic constant is a predefined PHP constant. its PHP magic constant _ METHOD _ description, constant _ method _

_ METHOD _ is a new magic constant after PHP5, indicating the name of the quasi-grammar. A magic constant is a PHP predefined constant whose values can be changed, other existing magic constants in PHP include _ LINE _, _ FILE _, _ FUNCTION _, and _ CLASS.

The following uses a short piece of code to demonstrate the _ METHOD _ usage.

<? Phpclass chhua {function test () {echo _ METHOD __;}}$ e = new chhua (); $ e-> test (); // output: chhua: test


How to use PHP magic constants

Direct use
For example
To obtain the script file location
_ FILE __;
 

Where is the magic constant file in php? How can we see what is the defined magic constant?

Magic constant
The current row number in the _ LINE _ file.
The complete path and FILE name of The _ FILE. If it is used in a file to be included, the file name to be included is returned. Starting from PHP 4.0.2, __file _ always contains an absolute path (if it is a symbolic connection, it is an absolute path after resolution ), earlier versions sometimes contain a relative path.
The directory where the _ DIR _ file is located. If it is used in included files, the Directory of the included files is returned. It is equivalent to dirname (_ FILE __). Unless it is the root directory, the name of the directory does not include the slash at the end. (Added in PHP 5.3.0) =
_ FUNCTION name (new in PHP 4.3.0 ). Starting from PHP 5, this constant returns the name (case sensitive) when the function is defined ). In PHP 4, the value is always lowercase letters.
_ CLASS name (new in PHP 4.3.0 ). Starting from PHP 5, this constant returns the name (case sensitive) when the class is defined ). In PHP 4, the value is always lowercase letters. The class name includes the declared zone (for example, Foo \ Bar ). Note that _ CLASS _ from PHP 5.4 also applies to trait. When used in the trait method, __class _ is the name of the CLASS that calls the trait method.
_ TRAIT _ Trait name (new in PHP 5.4.0 ). Starting from PHP 5.4, this constant returns the name (case sensitive) of the trait definition ). The Trait name includes the declared region (for example, Foo \ Bar ).
_ METHOD _ class METHOD name (new PHP 5.0.0 ). Returns the name (case sensitive) when the method is defined ).
_ NAMESPACE _ name of the current NAMESPACE (case sensitive ). This constant is defined during compilation (new in PHP 5.3.0 ).

Magic
_ Construct () ,__ destruct () ,__ call () ,__ callStatic () ,__ get () ,__ set () ,__ isset (), __unset () ,__ sleep () ,__ wakeup () ,__ toString () ,__ invoke () ,__ set_state () and _ clone () and other methods are called "Magic methods" (Magic methods) in PHP ). You cannot use these method names when naming your own class methods unless you want to use their magic functions.

Generally
 

Vertex _ METHOD _ is a new magic constant after PHP5, indicating the name of the quasi-grammar. A magic constant is a PHP predefined constant. its...

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.