PHP error_reporting: Complete Guide
The error_reporting function in PHP is used to set the level of error reporting, and its syntax is as follows:
error_reporting($level)
One option is to use the integer $level to specify the error reporting level. Here are some commonly used error reporting levels:
- Turn off all error reports.
- E_ERROR: Showing a fatal error.
- E_WARNING: Display Warning
- E_PARSE: Displays a parsing error
- E_NOTICE: Display notification.
- Show all errors with E_ALL.
For example, to display all errors, the error reporting level can be set to E_ALL.
error_reporting(E_ALL);
Set the error reporting level to 0 to disable all error reports.
error_reporting(0);
Furthermore, you can also use the return value of the error_reporting function to obtain the current error reporting level.
$currentLevel = error_reporting();
It is important to note that the error_reporting function only takes effect at runtime. If you want to set the error reporting level at the beginning of a script, you can configure it in the php.ini file.