PHP provides a large number of predefined constants to any script which it runs. Many of these constants, however, are created by various extensions, and will only be present when those extensions are available, either via dynamic loading or because they have been compiled in.
There are eight magical constants that change depending on
where they are used. For example, the value of
__LINE__ depends on the line that it's
used on in your script. These special constants are
case-insensitive and are as follows:
||The current line number of the file.|
The full path and filename of the file. If used inside an include,
the name of the included file is returned.
Since PHP 4.0.2,
||The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(__FILE__). This directory name does not have a trailing slash unless it is the root directory. (Added in PHP 5.3.0.)|
||The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.|
||The class name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the class name as it was declared (case-sensitive). In PHP 4 its value is always lowercased. The class name includes the namespace it was declared in (e.g. Foo\Bar). Note that as of PHP 5.4 __CLASS__ works also in traits. When used in a trait method, __CLASS__ is the name of the class the trait is used in.|
||The trait name. (Added in PHP 5.4.0) As of PHP 5.4 this constant returns the trait as it was declared (case-sensitive). The trait name includes the namespace it was declared in (e.g. Foo\Bar).|
||The class method name. (Added in PHP 5.0.0) The method name is returned as it was declared (case-sensitive).|
||The name of the current namespace (case-sensitive). This constant is defined in compile-time (Added in PHP 5.3.0).|