int error_reporting ([ int $level ] )

The error_reporting () function sets the error_reporting directive at runtime. PHP has many levels of error, using this feature to set the script’s duration (runtime) level. If the optional level is not set, error_reporting () will return only the current error reporting level.

parameter¶

Level
The new error_reporting level. It accepts bitmask or named constants. It is strongly recommended that named constants be used to ensure compatibility with future versions. When you add an error level, the integer range increases, so earlier integer-based error levels do not always work as expected.

The available error level constants and the actual meaning of these error levels are described in the predefined constants.

Return value¶

If you do not specify a level parameter, the old error_reporting level or the current level is returned.

Change log

50

Example

Example # 1 error_reporting () Example

<?php

// Turn off all error reporting
error_reporting(0);

// Report simple running errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Reporting E_NOTICE can be good too (to report uninitialized
// variables or catch variable name misspellings ...)
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 (see changelog)
error_reporting(E_ALL);

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

// Same as error_reporting(E_ALL);
ini_set('error_reporting', E_ALL);

?>

51