PHP Magic Constants

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Insert
> Step 2: And Like the video. BONUS: You can also share it!

Remarks

Magic constants are distinguished by their __CONSTANTNAME__ form.

There are currently 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:

NameDescription
__LINE__The current line number of the file.
__FILE__The full path and filename of the file with symlinks resolved. If used inside an include, the name of the included file is returned.
__DIR__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.
__FUNCTION__The current function name
__CLASS__The class name. The class name includes the namespace it was declared in (e.g. Foo\Bar). When used in a trait method, __CLASS__ is the name of the class the trait is used in.
__TRAIT__The trait name. The trait name includes the namespace it was declared in (e.g. Foo\Bar).
__METHOD__The class method name.
__NAMESPACE__The name of the current namespace.

Most common use case for these constants is debugging and logging



Got any PHP Question?