Home > Article > Backend Development > How to set the php error reporting level?
How to set the error reporting level in php: 1. Modify the default value of error_reporting in the PHP configuration file php.ini; 2. Use the built-in error_reporting() function in PHP to set it.
Recommended: "PHP Video Tutorial"
The error reporting level in PHP refers to when the PHP script code is running , if an error occurs, it will be output to the tester in the form of an error prompt according to the error category (the error here is a broad error, including E_NOTICE, E_WARNING, E_ERROR fatal error, etc.).
There are two ways to set the error reporting level in PHP, namely modifying the PHP configuration file php.ini, and using the built-in error_reporting() function in PHP
Modify the PHP configuration file php.ini
Open the configuration file php.ini and check the default value of error reporting level error_reporting,
is as follows:
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT
means reporting all errors except E_DEPRECATED and E_STRICT.
Modify it to:
error_reporting=E_ALL & ~E_NOTICE
It means reporting all errors except E_NOTICE. This is also the most commonly used error reporting level. It will not report errors of the attention class (such as using an undefined variable).
Save it and it will take effect after restarting the web server.
Note: After setting error_reporting in this way, restart the web server and it will take effect permanently.
Use the error_reporting() function
The error_reporting() function specifies what kind of PHP errors you should report.
The error_reporting() function can set the error_reporting directive at runtime.
Syntax:
error_reporting(level);
Note: It can take effect immediately after using the error_reporting() function. But only in the area behind the error_reporting() function call in the current script.
Example:
error_reporting(0);//关闭错误报告 error_reporting(E_ALL);//报告所有错误 ini_set("error_reporting", E_ALL);//报告所有错误 等同 error_reporting(E_ALL); error_reporting(E_ALL ^ E_NOTICE); // 除了E_NOTICE之外,报告所有的错误 error_reporting(E_ERROR); // 只报告致命错误 echo error_reporting(E_ERROR | E_WARNING | E_NOTICE); // 只报告E_ERROR、E_WARNING 和 E_NOTICE三种错误
Commonly used error reporting levels in PHP
1 E_ERROR Reports fatal errors that cause the script to terminate.
2 E_Warning Report the warning class error at runtime (the script does not terminate and runs)
## 4 E_PARSE Report the syntax analysis error during compilation## 8 e_notice report notification class error, the script Errors may occur
32767 E_ALL Report all possible errors (different PHP versions, the value of the constant E_ALL may also be different)
Want For more relevant knowledge, please visit:
Programming TeachingThe above is the detailed content of How to set the php error reporting level?. For more information, please follow other related articles on the PHP Chinese website!