Error Reporting Level: Specifies the circumstances under which the error in the script code (where the error is generalized, including E_NOTICE
attention, E_WARNING
warning, E_ERROR
fatal error, etc.) is output in the form of an error report.
To set the error reporting level method: 1. Modify the PHP configuration file php.ini
Once this is set up, restarting the error_reporting
Web server will take effect forever.
Open the configuration file php.ini
and view the default values for error reporting levels error_reporting
, as follows:
error_reporting=E_ALL & ~E_DEPRECATED & ~E_STRICT
It means to report all errors, but in addition to E_DEPRECATED
E_STRICT
these two kinds.
Modify it to:
error_reporting=E_ALL & ~E_NOTICE
It means to report all errors, but except for E_NOTICE
this one. This is also the most commonly used error reporting level, and it does not report errors that note classes (such as those that use undefined variables).
Save and take effect after restarting the Web server.
2. Using the error_reporting () function
This mode can be applied immediately after it is set. But limited to the following area of the function call in the current script error_reporting()
.
int error_reporting ([ int $level ] )
The parameter can be an integer or a corresponding constant identifier, and it is recommended to use the form of a constant. The return value is the value of the error report level at the current position (integer value).
Some error reporting levels are listed below:
值 常量 说明1 E_ERROR 报告导致脚本终止运行的致命错误2 E_WARNING 报告运行时的警告类错误(脚本不会终止运行)4 E_PARSE 报告编译时的语法解析错误8 E_NOTICE 报告通知类错误,脚本可能会产生错误32767 E_ALL 报告所有的可能出现的错误(不同的PHP版本,常量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三种错误
Note: php.ini
display_errors
The default value in the configuration file is on, which indicates that an error message is displayed, and if set to Off
, all error prompts are turned off.
Use error_reporting(0)
or add in front of the function to @
抑制错误输出
prevent error messages from leaking sensitive information.
PHP Error level settings