You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.