In
php, we often use the error_reportingfunction when handling errors. The
error_reporting() function tells you what kind of PHP errors should be reported. This function enables setting the error_reporting directive at runtime.
PHP has many error levels. Use this function to set the level when the script is running. If the optional parameter level is not set, error_reporting() will only return the current error reporting level.
The one you can see most is error_reporting(E_ALL ^ E_NOTICE). What does this mean? Let me take a look.
First of all, you must know that the error_reporting() function is used to set the error level and return the current level. It has 14 error levels, as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
It seems that php does not enable errors by default, so you need to configure the php.ini file:
Change display_errors = Off changed to display_errors = On
Also configure the error level: Change
error_reporting = E_ALL to:
error_reporting = E_ALL & ~E_NOTICE
It should be that php displays all errors by default, and we do not need to display some harmless prompts, so the settings are as above!
Can also be used in php code as follows:
1 2 3 4 5 6 7 8 |
|
The above is the detailed content of Detailed explanation of the usage of php error_reporting() function. For more information, please follow other related articles on the PHP Chinese website!