PHP Reference ยท Variables and Constants
PHP error level constants
Reference for PHP error level constants: E_ALL, E_ERROR, E_WARNING, E_NOTICE, E_DEPRECATED and E_USER_*, their values, bitmasks and how to combine them.
The E_* constants name the kinds of problems PHP can report. Each one is a power of two, so they can be combined into a bitmask and used with error_reporting(), the error_reporting ini setting, and set_error_handler(). A level answers two questions: how serious is the problem, and does PHP stop the script?
Since PHP 8, many old notices and warnings became exceptions (TypeError, ValueError, DivisionByZeroError), so you meet fatal levels less often as ordinary messages and more often as uncaught exceptions. Warnings and deprecations are still reported through these levels.
<?php error_reporting(E_ALL & ~E_DEPRECATED); // everything except deprecations
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.
The constants
| Constant | Value | Meaning |
|---|---|---|
E_ERROR |
1 | Fatal runtime error. The script stops. |
E_WARNING |
2 | Runtime warning. The script continues. |
E_PARSE |
4 | Syntax error at compile time. |
E_NOTICE |
8 | Runtime notice, usually a likely bug (for example an undefined index in old code). |
E_CORE_ERROR |
16 | Fatal error during PHP's startup. |
E_CORE_WARNING |
32 | Warning during PHP's startup. |
E_COMPILE_ERROR |
64 | Fatal compile-time error. |
E_COMPILE_WARNING |
128 | Compile-time warning. |
E_USER_ERROR |
256 | User-generated error, raised with trigger_error(). |
E_USER_WARNING |
512 | User-generated warning. |
E_USER_NOTICE |
1024 | User-generated notice. |
E_STRICT |
2048 | Removed as a level in PHP 8.4; the constant is deprecated. |
E_RECOVERABLE_ERROR |
4096 | Catchable fatal error (rare in PHP 8, mostly replaced by TypeError). |
E_DEPRECATED |
8192 | The feature still works but will be removed. |
E_USER_DEPRECATED |
16384 | User-generated deprecation. |
E_ALL |
30719 | All errors and warnings (PHP 8.4 and later). |
The value of E_ALL was 32767 in PHP 8.3 and earlier, because E_STRICT was still included. Always use the constant, never the number.
Usage notes
- Combine with bit operators.
E_ALL & ~E_NOTICEmeans "everything except notices";E_ERROR | E_WARNINGmeans "only those two". The~operator inverts,&keeps,|adds,^toggles. - Development: report everything. Use
error_reporting = E_ALLanddisplay_errors = 1locally. Production: keepE_ALL, setdisplay_errors = 0andlog_errors = 1, so problems are recorded but never shown to visitors. - Not every level can be handled. A handler set with
set_error_handler()never seesE_ERROR,E_PARSE,E_CORE_*andE_COMPILE_*. Useregister_shutdown_function()together witherror_get_last()to log those. E_USER_ERRORwithtrigger_error()stops the script unless a handler returnstrue. As of PHP 8.4 passingE_USER_ERRORtotrigger_error()is deprecated. Throw an exception instead.- Level and exception are different. Most PHP 8 errors are
Errorexceptions you catch withcatch (Error $e). Warnings are not exceptions; convert them with a handler that throwsErrorException. @silences, but not fully. The@operator lowers reporting for one expression, and since PHP 8 it no longer hides fatal errors. Prefer checking the condition (isset,file_exists) over silencing.E_NOTICEis rarer now. PHP 8 promoted many notices (undefined variables, array keys, offsets) to warnings.E_STRICT. Removed from active use in PHP 8.4; reading the constant prints a deprecation message.