This article mainly introduces the usage of error_reporting functions in PHP. For more information about error_reporting functions in PHP, see the following article, for more information, see
Error_reporting function usage in PHP
The error_reporting function is used to handle errors in PHP. The most common error is error_reporting (E_ALL ^ E_NOTICE). What does this mean? The following describes the error_reporting function.
Define usage
Error_reporting () sets the PHP error level and returns the current level.
Syntax
error_reporting(report_level)
If the report_level parameter is not specified, the current error level is returned. The following items are possible values of report_level:
Value |
Constant |
Description |
1 |
E_ERROR |
Fatal runtime error. Unrecoverable errors. Stop the script execution. |
2 |
E_WARNING |
Non-fatal runtime error. Script execution is not stopped. |
4 |
E_PARSE |
Compilation error. |
8 |
E_NOTICE |
Runtime reminder. |
16 |
E_CORE_ERROR |
A fatal error during PHP startup. This is like an E_ERROR at the PHP core. |
32 |
E_CORE_WARNING |
Non-fatal errors during PHP startup. This is like a warning on PHP core E_WARNING. |
64 |
E_COMPILE_ERROR |
Fatal compile-time error. This is like an E_ERROR generated by the Zend script engine. |
128 |
E_COMPILE_WARNING |
Non-fatal compile-time error. The Zend script engine generates an E_WARNING warning. |
256 |
E_USER_ERROR |
User-defined fatal error |
512 |
E_USER_WARNING |
User-defined warning (non-fatal error) |
1024 |
E_USER_NOTICE |
User-defined notifications (often bugs, or intentionally) |
2048 |
E_STRICT |
Code Standardization warning (how to modify to forward compatibility) |
4096 |
E_RECOVERABLE_ERROR |
Near fatal runtime error. if not captured, it is considered as E_ERROR. |
8191 |
E_ALL |
All errors except E_STRICT |
PHP does not enable errors by default, so you need to configure the php. ini file:
Change display_errors = Off to display_errors = On.
In addition, you need to configure the error level. because PHP displays all errors by default, and some harmless prompts are not required, the settings are as follows:
Change error_reporting = E_ALL to error_reporting = E_ALL &~ E_NOTICE
Example of using PHP code:
Tip: any number of the above options can be connected with "OR" (OR |), so that all the required levels of errors can be reported. For example, the following code disables user-defined errors and warnings, performs some operations, and then restores to the original error level:
To learn how the error_reporting function is used, read the error_reporting (E_ALL ^ E_NOTICE) code, which means to display all error messages except E_NOTICE.
The above is the details of the error_reporting function instance tutorial in PHP. For more information, see other related articles in the first PHP community!