Skip to content

Instantly share code, notes, and snippets.

@MrPunyapal
Last active June 30, 2025 03:51
Show Gist options
  • Save MrPunyapal/2e46c50880ef5a0cfd363e1700b78a79 to your computer and use it in GitHub Desktop.
Save MrPunyapal/2e46c50880ef5a0cfd363e1700b78a79 to your computer and use it in GitHub Desktop.
PHP Constants Cheat Sheet (8.4 Ready)

🧾 PHP Constants Cheat Sheet (with Examples) β€” PHP 8.4 Ready

A clean and categorized reference of the most useful constants in PHP.
Includes descriptions and sample outputs for context. Fully valid for PHP 8.3 and safe for PHP 8.4.


πŸ—‚ Filesystem & Path Constants

Constant Description Example Output
DIRECTORY_SEPARATOR Path separator (/ on Unix, \ on Windows) /
PATH_SEPARATOR Include path separator (: or ;) :
__FILE__ Full path and filename of the current file /var/www/html/index.php
__DIR__ Directory of the current file /var/www/html
__LINE__ Line number in the file 42

🧠 Magic Constants

Constant Description Example Output
__FUNCTION__ Current function name myFunction
__CLASS__ Current class name MyClass
__TRAIT__ Current trait name MyTrait
__METHOD__ Current class method MyClass::myMethod
__NAMESPACE__ Current namespace App\Controllers

πŸ–₯ PHP Environment & System Constants

Constant Description Example Output
PHP_VERSION Full PHP version 8.4.0-dev
PHP_MAJOR_VERSION Major version 8
PHP_MINOR_VERSION Minor version 4
PHP_RELEASE_VERSION Patch version 0
PHP_OS Operating system name (from compiler) Linux, WINNT, Darwin
PHP_OS_FAMILY General OS family (portable grouping) Linux, Windows, BSD, macOS
PHP_SAPI Server API type cli
PHP_EOL End-of-line character \n
PHP_INT_MAX Max integer supported 9223372036854775807
PHP_INT_MIN Min integer supported -9223372036854775808
PHP_FLOAT_MAX Max float supported 1.7976931348623E+308
PHP_FLOAT_MIN Min float supported 2.2250738585072E-308

🧾 Error Reporting Constants

Constant Description Error Type
E_ERROR Fatal run-time errors Fatal
E_WARNING Non-fatal run-time warnings Warning
E_PARSE Compile-time parse errors Fatal
E_NOTICE Notices about potential issues Notice
E_CORE_ERROR PHP core fatal errors Fatal
E_CORE_WARNING PHP core warnings Warning
E_COMPILE_ERROR Compile-time fatal errors Fatal
E_COMPILE_WARNING Compile-time warnings Warning
E_USER_ERROR User-generated fatal error Fatal
E_USER_WARNING User-generated warning Warning
E_USER_NOTICE User-generated notice Notice
E_STRICT Suggests code improvements Best practice
E_RECOVERABLE_ERROR Catchable fatal error Fatal (catchable)
E_DEPRECATED Deprecated feature used Warning
E_USER_DEPRECATED User-generated deprecation notice Warning
E_ALL All error levels Aggregate

πŸ“ File Upload Error Constants

Constant Description Code
UPLOAD_ERR_OK No error, file uploaded successfully 0
UPLOAD_ERR_INI_SIZE File exceeds upload_max_filesize in php.ini 1
UPLOAD_ERR_FORM_SIZE File exceeds MAX_FILE_SIZE in HTML form 2
UPLOAD_ERR_PARTIAL File was only partially uploaded 3
UPLOAD_ERR_NO_FILE No file was uploaded 4
UPLOAD_ERR_NO_TMP_DIR Missing temporary folder 6
UPLOAD_ERR_CANT_WRITE Failed to write file to disk 7
UPLOAD_ERR_EXTENSION Upload stopped by a PHP extension 8

πŸ’» CLI Stream Constants

Constant Description Available In
STDIN Standard input stream CLI only
STDOUT Standard output stream CLI only
STDERR Standard error stream CLI only

πŸ“Œ Tip: These constants are built into PHP β€” no import or setup needed.
🧠 Valid for PHP 8.3+ and future-proof for PHP 8.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment