error_reporting Error Level Variable Comparison Table for PHP

  • 2021-07-07 06:47:46
  • OfStack

All error messages in PHP can be set using the function error_reporting ():

Its parameters are expressed in two ways: string and number, with a total of 14 grades. However, I think it seems that it is ok to use other numbers. At first I thought it meant a fixed error reporting interval. Later, I finally discovered the law:

error_reporting( 7 ) = error_reporting( 1+2+4)= error_reporting(E_ERROR | E_WARING | E_PARSE)

Now, I sum it up as follows:

数字 常量 说明
1 E_ERROR 致命错误,脚本执行中断,就是脚本中有不可识别的东西出现
举例: Error:Invalid parameters. Invalid parameter name
2 E_WARNING 部分代码出错,但不影响整体运行
举例: Warning: require_once(E:/include/config_base.php)
4 E_PARSE  字符、变量或结束的地方写规范有误
举例:  Parse error: syntax error, unexpected $end in
 E_NOTICE 1般通知,如变量未定义等
举例:  Notice: Undefined variable: p in E:\web\index.php on line 17
16  E_CORE_ERROR PHP进程在启动时,发生了致命性错误
举例:  暂无
32  E_CORE_WARNING 在PHP启动时警告(非致命性错误)
举例:  暂无
64 E_COMPILE_ERROR 编译时致命性错误
举例:  暂无
128 E_COMPILE_WARNING 编译时警告级错误
举例:  暂无
256 E_USER_ERROR  用户自定义的错误消息
举例:  暂无
512 E_USER_WARNING 用户自定义的警告消息
举例:  暂无
1024 E_USER_NOTICE  用户自定义的提醒消息
举例:  暂无
2047 E_ALL 以上所有的报错信息,但不包括E_STRICT的报错信息
举例:  暂无
2048 E_STRICT 编码标准化警告,允许PHP建议如何修改代码以确保最佳的互操作性向前兼容性。

The default value for the error_reporting variable is E_ALL & ~E_NOTICE
When developing, the best value is: E_ALL E_STRICT

If set to: error_reporting (E_ALL E_STRICT), all error messages are logged
May cause a lot of error codes on the website; But for programmers, it should be said to be a good thing, which can optimize the code to the best; 1 Some non-fatal errors do not affect the operation of the program, but will increase the burden of PHP.


Finally, the English version of the comparison table:

1 E_ERROR Fatal run-time errors. Errors that can not be recovered from. Execution of the script is halted
2 E_WARNING Non-fatal run-time errors. Execution of the script is not halted
4 E_PARSE Compile-time parse errors. Parse errors should only be generated by the parser
8 E_NOTICE Run-time notices. The script found something that might be an error, but could also happen when running a script normally
16 E_CORE_ERROR Fatal errors at PHP startup. This is like an E_ERROR in the PHP core
32 E_CORE_WARNING Non-fatal errors at PHP startup. This is like an E_WARNING in the PHP core
64 E_COMPILE_ERROR Fatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine
128 E_COMPILE_WARNING Non-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine
256 E_USER_ERROR Fatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error()
512 E_USER_WARNING Non-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error()
1024 E_USER_NOTICE User-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error()
2048 E_STRICT Run-time notices. PHP suggest changes to your code to help interoperability and compatibility of the code
4096 E_RECOVERABLE_ERROR Catchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler())
8191 E_ALL All errors and warnings, except level E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0)

Related articles: