PHP Reference ยท Variables and Constants
PHP predefined constants
Reference for PHP predefined constants: PHP_EOL, PHP_INT_MAX, PHP_FLOAT_EPSILON, PHP_VERSION, PHP_OS_FAMILY, DIRECTORY_SEPARATOR, M_PI and what each is for.
PHP defines a large set of constants before your script runs. Core constants such as PHP_EOL and PHP_INT_MAX are always available; others (M_PI, JSON_PRETTY_PRINT, SORT_STRING, E_ALL) belong to extensions and are available when the extension is loaded. Constants have no $, are case-sensitive, and cannot be changed.
This page covers the constants about the PHP build, the platform and number limits. Error level constants are in Error level constants, and __LINE__ and friends are in Magic constants.
<?php echo "PHP " . PHP_VERSION . PHP_EOL; echo PHP_INT_MAX;
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with fgets(STDIN)), it gets the next line from this box.
Reference
| Constant | Meaning |
|---|---|
PHP_EOL |
The platform's line ending: "\n" on Linux and macOS, "\r\n" on Windows. |
PHP_VERSION |
Full version string, such as 8.5.8. |
PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION |
The three numbers as integers. |
PHP_VERSION_ID |
One integer, major * 10000 + minor * 100 + release. Good for >= checks. |
PHP_EXTRA_VERSION |
Extra text such as -dev or a distribution suffix; usually empty. |
PHP_OS |
Operating system PHP was built for, such as Linux or WINNT. |
PHP_OS_FAMILY |
Windows, BSD, Darwin, Solaris, Linux or Unknown (PHP 7.2). |
PHP_SAPI |
Server API in use: cli, fpm-fcgi, apache2handler, cli-server... |
DIRECTORY_SEPARATOR |
/ or \. |
PATH_SEPARATOR |
: or ;, used in PATH style lists. |
PHP_MAXPATHLEN |
Longest file path the build supports. |
PHP_INT_MAX, PHP_INT_MIN, PHP_INT_SIZE |
Integer limits and size in bytes (8 on 64-bit). |
PHP_FLOAT_EPSILON, PHP_FLOAT_MIN, PHP_FLOAT_MAX, PHP_FLOAT_DIG |
Float precision facts (PHP 7.2). PHP_FLOAT_MIN is the smallest positive normal number, not the most negative. |
NAN, INF |
Not-a-number and infinity. |
M_PI, M_E, M_SQRT2, M_LN2... |
Math constants. |
PHP_BINARY |
Path to the PHP executable (CLI). |
PHP_DEBUG, PHP_ZTS |
1 for debug or thread-safe builds, otherwise 0. |
STDIN, STDOUT, STDERR |
Open streams in the CLI only. |
Usage notes
- Use
PHP_EOLfor text meant for files and the console. In HTML output a plain"\n"is fine, browsers ignore it anyway. - Compare versions with
PHP_VERSION_IDorversion_compare(), not by comparingPHP_VERSIONas strings:"8.10.0" < "8.9.0"as text. - Integer overflow produces floats.
PHP_INT_MAX + 1is a float, not a wrapped negative number. On 32-bit buildsPHP_INT_MAXis 2147483647. PHP_FLOAT_EPSILONis the gap between1.0and the next larger float. It is a tolerance for numbers near 1, not an absolute tolerance for all numbers; scale it for large or small values.NANis never equal to anything. Test withis_nan(), andINFwithis_infinite().- Do not hard-code separators.
DIRECTORY_SEPARATORhelps with Windows; PHP itself also accepts/in paths on Windows. - Check
defined("NAME")or useconstant("NAME")when a constant may not exist (extension missing, newer PHP version). Reading an undefined constant throwsError: Undefined constant. - Your own constants are created with
constordefine(). PHP_SAPIandphp_sapi_name()return the same value; see PHP_SAPI.- Constants can be deprecated.
E_STRICTis deprecated since PHP 8.4 because the error level it stood for was removed; using it prints a deprecation message (see Error level constants).