PHP Magic constants

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:
A few "magical" PHP constants
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 function name.
__CLASS__The class name. 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.
__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.

Predefined Constants

These constants are defined by the PHP core. This includes PHP, the Zend engine, and SAPI modules.
PHP_VERSION (string)
The current PHP version as a string in "major.minor.release[extra]" notation.
PHP_MAJOR_VERSION (integer)
The current PHP "major" version as an integer (e.g., int(5) from version "5.2.7-extra"). Available since PHP 5.2.7.
PHP_MINOR_VERSION (integer)
The current PHP "minor" version as an integer (e.g., int(2) from version "5.2.7-extra"). Available since PHP 5.2.7.
PHP_RELEASE_VERSION (integer)
The current PHP "release" version as an integer (e.g., int(7) from version "5.2.7-extra"). Available since PHP 5.2.7.
PHP_VERSION_ID (integer)
The current PHP version as an integer, useful for version comparisons (e.g., int(50207) from version "5.2.7-extra"). Available since PHP 5.2.7.
PHP_EXTRA_VERSION (string)
The current PHP "extra" version as a string (e.g., '-extra' from version "5.2.7-extra"). Often used by distribution vendors to indicate a package version. Available since PHP 5.2.7.
PHP_ZTS (integer)
Available since PHP 5.2.7.
PHP_DEBUG (integer)
Available since PHP 5.2.7.
PHP_MAXPATHLEN (integer)
The maximum length of filenames (including path) supported by this build of PHP. Available since PHP 5.3.0.
PHP_OS (string)
PHP_SAPI (string)
The Server API for this build of PHP. See also php_sapi_name().
PHP_EOL (string)
The correct 'End Of Line' symbol for this platform. Available since PHP 5.0.2
PHP_INT_MAX (integer)
The largest integer supported in this build of PHP. Usually int(2147483647). Available since PHP 5.0.5
PHP_INT_MIN (integer)
The smallest integer supported in this build of PHP. Usually int(-2147483648) in 32 bit systems and int(-9223372036854775808) in 64 bit systems. Available since PHP 7.0.0. Usually, PHP_INT_MIN === ~PHP_INT_MAX.
PHP_INT_SIZE (integer)
The size of an integer in bytes in this build of PHP. Available since PHP 5.0.5
DEFAULT_INCLUDE_PATH (string)
PEAR_INSTALL_DIR (string)
PEAR_EXTENSION_DIR (string)
PHP_EXTENSION_DIR (string)
PHP_PREFIX (string)
The value "--prefix" was set to at configure.
PHP_BINDIR (string)
Specifies where the binaries were installed into.
PHP_BINARY (string)
Specifies the PHP binary path during script execution. Available since PHP 5.4.
PHP_MANDIR (string)
Specifies where the manpages were installed into. Available since PHP 5.3.7.
PHP_LIBDIR (string)
PHP_DATADIR (string)
PHP_SYSCONFDIR (string)
PHP_LOCALSTATEDIR (string)
PHP_CONFIG_FILE_PATH (string)
PHP_CONFIG_FILE_SCAN_DIR (string)
PHP_SHLIB_SUFFIX (string)
The build-platform's shared library suffix, such as "so" (most Unixes) or "dll" (Windows).
E_ERROR (integer)
Error reporting constant
E_WARNING (integer)
E_PARSE (integer)
E_NOTICE (integer)
E_CORE_ERROR (integer)
E_CORE_WARNING (integer)
E_COMPILE_ERROR (integer)
E_COMPILE_WARNING (integer)
E_USER_ERROR (integer)
E_USER_WARNING (integer)
E_USER_NOTICE (integer)
E_DEPRECATED (integer)
Available since PHP 5.3.0
E_USER_DEPRECATED (integer)
Available since PHP 5.3.0
E_ALL (integer)
E_STRICT (integer)
__COMPILER_HALT_OFFSET__ (integer)
Available since PHP 5.1.0
TRUE (boolean)
See Booleans.
FALSE (boolean)
See Booleans.
NULL (null)
See Null.