PHP "magic constant"

Source: Internet
Author: User
PHP provides a large number of predefined constants to any script it runs. However, many constants are defined by different extension libraries. only when these extension libraries are loaded

PHP provides a large number of predefined constants to any script it runs. However, many constants are defined by different extension libraries. they only appear when these extension libraries are loaded, dynamically loaded, or included during compilation. There are seven magic constants whose values change with their positions in the code. For example, the value of _ LINE _ depends on the rows in the script. These special constants are case-insensitive, as follows:

Name Description
_ LINE __ The current row number in the file. Through editplus, we can intuitively see
_ FILE __ The complete file path and file name. If it is used in a file to be included, the file name to be included is returned. Since PHP 4.0.2,_ FILE __It always contains an absolute path (if it is a symbolic link, it is the absolute path after resolution), and the previous version sometimes contains a relative path.
_ DIR __ The directory where the file is located. If it is used in included files, the Directory of the included files is returned. It is equivalentDirname (_ 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 __ Function name (new 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 __ Class name (new 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.
_ 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)

Note: PHP magic constants are followed by two underscores.


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.