The error_reporting() is a pre-defined function of PHP. It allows you to control how many and which PHP errors will be reported. As we already discussed that PHP has several levels of errors. Using the error_reporting() function sets that level for the duration of your current script.
The php.ini file has an error_reporting directive that will be set at runtime by this function.
error_reporting (int $level)
The $level is an optional parameter in error_reporting() function. If the level is not set, this function will return the current error reporting level.
level (Optional)
This parameter specifies the error-report level for the current script.
If the level parameter is not given, it will return the current level. Otherwise, it will revert to the old error_reporting level.
Versions | Description |
---|---|
PHP 5.4 | E_STRICT has become a part of E_ALL. |
PHP 5.3
|
E_DEPRECATED and E_USER_DEPRECATED are newly added in PHP 5.3. |
PHP 5.2 | E_RECOVERABLE_ERROR is added in PHP 5.2. |
PHP 5.0 | E_STRICT is newly introduced in PHP 5.0. |
With the help of PHP program specify different levels of error reporting:
<? // Turn off all error reporting error_reporting(0); // Report all PHP errors error_reporting(E_ALL); // Report all PHP errors error_reporting(-1); // Report all errors except E_NOTICE error_reporting(E_ALL & ~E_NOTICE); // Report simple running errors error_reporting(E_WARNING | E_ERROR | E_PARSE); // E_NOTICE is also good to report uninitialized variables error_reporting( E_WARNING |E_ERROR | E_PARSE | E_NOTICE); // It is same as error_reporting(E_ALL); ini_set('error_reporting', E_LL); ?>
error_reporting(0);
error_reporting(E_NOTICE);
error_reporting(E_ALL & ~E_NOTICE)
error_reporting(-1); error_reporting(E_ALL) ini_set('error_reporting', E_ALL);