Menu
[ ← back to blog ]

Commonly used constants in PHP

A quick reference of commonly used PHP core constants (EOL markers, integer limits, float ranges) and why they matter for portable code.

phpconstantsreferencebest-practicestutorial

These constants are defined by the PHP core.

ConstantDescription
PHP_EOLThe correct ‘End Of Line’ symbol for this platform. Available since PHP 5.0.2
PHP_INT_MAXThe largest integer supported in this build of PHP. Usually int(2147483647) in 32 bit systems and int(9223372036854775807) in 64 bit systems. Available since PHP 5.0.5
PHP_INT_MINThe 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_SIZEThe size of an integer in bytes in this build of PHP. Available since PHP 5.0.5
PHP_FLOAT_EPSILONSmallest representable positive number x, so that x + 1.0 != 1.0. Available as of PHP 7.2.0.
PHP_FLOAT_MINSmallest representable floating point number. Available as of PHP 7.2.0.
PHP_FLOAT_MAXLargest representable floating point number. Available as of PHP 7.2.0.

Note

It is better to use PHP_EOL when you need to put new line characters. Since the difference between new line characters in different systems, PHP_EOL can improve the portability of your codes to some extent.

References


PW
Paul Wen
Replied just now
Hello! Thanks for reaching out.
I'm currently open to new opportunities. How would you like to connect?