Home  >  Article  >  Backend Development  >  What are the magic constants in php?

What are the magic constants in php?

怪我咯
怪我咯Original
2017-06-20 10:33:561806browse

In php we can customize constants. At the same time, php has also customized some useful constants. These constants will automatically change according to their location. We call it Magic Constant.

There are eight magic constants in php:

  • LINE The current line number in the file.

  • #FILE The full path and file name of the file. If used in an included file, returns the included file name. Since PHP 4.0.2, FILE always contains an absolute path (or the resolved absolute path in the case of a symbolic link), while versions before that sometimes contained a relative path.

  • #DIR The directory where the file is located. If used within an included file, returns the directory where the included file is located. It is equivalent to dirname(FILE). Directory names do not include the trailing slash unless they are the root directory. (New in PHP 5.3.0) =

  • FUNCTION Function name (New in PHP 4.3.0). Since PHP 5 this constant returns the name of the function as it was defined (case sensitive). In PHP 4 this value is always lowercase.

  • CLASS The name of the class (newly added in PHP 4.3.0). Since PHP 5 this constant returns the name of the class when it was defined (case sensitive). In PHP 4 this value is always lowercase. The class name includes the scope in which it is declared (e.g. Foo\Bar). Note that as of PHP 5.4 CLASS also works for traits. When used within a trait method, CLASS is the name of the class that calls the trait method.

  • TRAIT The name of Trait (newly added in PHP 5.4.0). Since PHP 5.4 this constant returns the name of the trait as it was defined (case-sensitive). The trait name includes the scope in which it is declared (e.g. Foo\Bar).

  • METHOD The method name of the class (newly added in PHP 5.0.0). Returns the name of the method as it was defined (case-sensitive).

  • NAMESPACE The name of the current namespace (case-sensitive). This constant is defined at compile time (new in PHP 5.3.0).

The above is the detailed content of What are the magic constants in php?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn