English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP error_reporting() Function Usage and Examples

PHP Error & Loggings Reference Manual

The error_reporting() function sets which PHP errors should be reported

Syntax

int error_reporting([int $level]);

Definition and usage

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.

Parameter

NumberParameters and descriptions
1

level(可选)

It specifies the error reporting level of the current script. Accepts numeric values and constant names.

Report level

ValueConstantDescription
1E_ERRORFatal errors at runtime. Unrepairable errors. The script execution stops.
2E_WARNINGNon-fatal errors at runtime. The script did not stop executing.
4E_PARSEParsing errors during compilation. Parsing errors should only be generated by the parser.
8E_NOTICENotifications at runtime. The script found something that might be an error, but it could also occur during normal script execution.
16E_CORE_ERRORFatal errors at PHP startup. This is similar to E_ERROR in PHP core.
32E_CORE_WARNINGNon-fatal errors at PHP startup. This is similar to E_WARNING in PHP core.
64E_COMPILE_ERRORA fatal error during compilation. This is similar to E_ERROR generated by the Zend script engine.
128E_COMPILE_WARNINGCompile-time non-fatal errors. This is like an E_WARNING generated by the Zend script engine.
256E_USER_ERRORUser-generated fatal errors. This is like an E_ERROR generated by a programmer using the PHP function trigger_error().
512E_USER_WARNINGUser-generated non-fatal errors. This is like an E_WARNING generated by a programmer using the PHP function trigger_error().
1024E_USER_NOTICEUser-generated notices. This is like an E_NOTICE generated by a programmer using the PHP function trigger_error().
2048E_STRICTRun-time notices. PHP recommends that you change the code to improve interoperability and compatibility.
4096E_RECOVERABLE_ERRORCatchable fatal errors. This is like an E_ERROR that can be caught by a user-defined handler (see set_error_handler()).
8191E_ALLAll error and warning levels, except E_STRICT (since PHP 6.0 onwards, E_STRICT will be part of E_ALL).

Return value

 Returns the old error_reporting level, or the current level if no level parameter is given.

Online example

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);
?>