PHP Function Reference

PHP error_reporting() Function



The PHP error_reporting() function is used to set which PHP errors are reported. PHP has many levels of errors, using this function sets that level for the current script.

Syntax

error_reporting(error_level)

Parameters

error_level Optional. Specify the error_reporting level for the current script. It takes on either a bitmask, or named constants which are described in the predefined constants. Using named constants is recommended to ensure compatibility for future versions.

Return Value

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

Example: error_reporting() example

The example below shows the usage of error_reporting() function.

<?php
//turn off all error reporting
error_reporting(0);

//report simple runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

//report simple runtime errors and E_NOTICE 
error_reporting(E_ERROR | E_WARNING | E_PARSE | E_NOTICE);

//report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);

//report all PHP errors
error_reporting(E_ALL);

//report all PHP errors
error_reporting(-1);

//same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);
?>

❮ PHP Error Handling Reference