English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
PHP Error & Loggings Reference Manual
The error_reporting() function sets which PHP errors should be reported
int error_reporting([int $level]);
The error_reporting() function can set the error_reporting directive at runtime. PHP has many error levels, and this function can set the level at runtime. If the optional parameter level is not set, error_reporting() will only return the current error reporting level.
Number | Parameters and descriptions |
---|---|
1 | level(可选) It specifies the error reporting level of the current script. Accepts numeric values and constant names. |
Value | Constant | Description |
---|---|---|
1 | E_ERROR | Fatal errors at runtime. Unrepairable errors. The script execution stops. |
2 | E_WARNING | Non-fatal errors at runtime. The script did not stop executing. |
4 | E_PARSE | Parsing errors during compilation. Parsing errors should only be generated by the parser. |
8 | E_NOTICE | Notifications at runtime. The script found something that might be an error, but it could also occur during normal script execution. |
16 | E_CORE_ERROR | Fatal errors at PHP startup. This is similar to E_ERROR in PHP core. |
32 | E_CORE_WARNING | Non-fatal errors at PHP startup. This is similar to E_WARNING in PHP core. |
64 | E_COMPILE_ERROR | A fatal error during compilation. This is similar to E_ERROR generated by the Zend script engine. |
128 | E_COMPILE_WARNING | Compile-time non-fatal errors. This is like an E_WARNING generated by the Zend script engine. |
256 | E_USER_ERROR | User-generated fatal errors. This is like an E_ERROR generated by a programmer using the PHP function trigger_error(). |
512 | E_USER_WARNING | User-generated non-fatal errors. This is like an E_WARNING generated by a programmer using the PHP function trigger_error(). |
1024 | E_USER_NOTICE | User-generated notices. This is like an E_NOTICE generated by a programmer using the PHP function trigger_error(). |
2048 | E_STRICT | Run-time notices. PHP recommends that you change the code to improve interoperability and compatibility. |
4096 | E_RECOVERABLE_ERROR | Catchable fatal errors. This is like an E_ERROR that can be caught by a user-defined handler (see set_error_handler()). |
8191 | E_ALL | All error and warning levels, except E_STRICT (since PHP 6.0 onwards, E_STRICT will be part of E_ALL). |
Returns the old error_reporting level, or the current level if no level parameter is given.
The following is the usage of the error_reporting function-
<?php // Turns off all PHP error reporting error_reporting(0); // Reports simple runtime errors error_reporting(E_ERROR | E_WARNING | E_PARSE); // Reporting E_NOTICE is also good (reports uninitialized variables) // Or catch variable name spelling errors) error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE); // Reports all errors except E_NOTICE error_reporting(E_ALL ^ E_NOTICE); // Reports all PHP errors (see changelog) error_reporting(E_ALL); // Reports all PHP errors error_reporting(-1); // It is the same as error_reporting(E_ALL); ini_set('error_reporting', E_ALL); ?>