A few PHP "Magic constants"

Source: Internet
Author: User
Tags constant contains lowercase root directory

PHP provides a large number of predefined constants to any script it runs. However, many constants are defined by different extensions, and are only available when the extensions are loaded, either dynamically or at compile time.

There are seven magic constants whose values change as they position in the code. For example, the value of __line__ depends on the line in which it is located in the script. These special constants are case-insensitive, as follows:

name Description
__line__ The current line number in the file.
__file__ The full path and file name of the file. If used in the included file, the included file name is returned. Since PHP 4.0.2,__file__ always contains an absolute path (if the symbolic connection is a parsed absolute path), and the previous version sometimes contains a relative path.
__dir__ The directory in which the 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). From PHP 5 This constant returns the name (case-sensitive) of the function when it is defined. This value is always lowercase in PHP 4.
__class__ The name of the class (PHP 4.3.0 new). From PHP 5 This constant returns the name of the class when it is defined (case-sensitive). This value is always lowercase in PHP 4.
__method__ The method name of the class (PHP 5.0.0 new). Returns the name (case-sensitive) of the method when it is defined.
__namespace__ The name of the current namespace (case sensitive). This constant is defined at compile time (PHP 5.3.0 new)


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.