PHP的error_reporting错误级别变量对照表


Posted in PHP onJuly 08, 2014

在PHP中所有的报错信息可以用error_reporting()这个函数来设置:

它的参数有字符串和数字两种表示方法,共14个等级,但是呢,我看使用其他数字貌似也可以,起初我以为它指的是一定的报错区间,后来,终于发现了其中的规律:

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

现在,我将其总结如下:

数字 常量 说明
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 一般通知,如变量未定义等 举例:  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建议如何修改代码以确保最佳的互操作性向前兼容性。

error_reporting 变量的默认值是  E_ALL & ~E_NOTICE
开发时,最佳的值为: E_ALL | E_STRICT

如果设置为:error_reporting(E_ALL | E_STRICT),则表示记录所有的错误信息
可能会导致网站出现一大堆的错误代码;但是对于程序员来说应该说是一件好事,可以把代码优化到最优; 一些非致命性错误虽然不影响程序的运行,但是会加重PHP的负担.

最后,晒出英文版的对照表:

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)
PHP 相关文章推荐
php 前一天或后一天的日期
Jun 28 PHP
PHP Mysql编程之高级技巧
Aug 27 PHP
phpmailer发送gmail邮件实例详解
Jun 24 PHP
php中动态调用函数的方法
Mar 16 PHP
php编写简单的文章发布程序
Jun 18 PHP
php脚本运行时的超时机制详解
Feb 17 PHP
ThinkPHP模板Volist标签嵌套循环输出多维数组的方法
Mar 23 PHP
php时间函数用法分析
May 28 PHP
PHP基于简单递归函数求一个数阶乘的方法示例
Apr 26 PHP
tp5.1 实现setInc字段自动加1
Oct 18 PHP
php 下 html5 XHR2 + FormData + File API 上传文件操作实例分析
Feb 28 PHP
TP3.2框架分页相关实现方法分析
Jun 03 PHP
PHP获取客户端真实IP地址的5种情况分析和实现代码
Jul 08 #PHP
php+mysql不用递归实现的无限级分类实例(非递归)
Jul 08 #PHP
PHP生成短网址的3种方法代码实例
Jul 08 #PHP
PHP的fsockopen、pfsockopen函数被主机商禁用的解决办法
Jul 08 #PHP
php中函数前加&符号的作用分解
Jul 08 #PHP
PHP实现的连贯操作、链式操作实例
Jul 08 #PHP
PHP类中的魔术方法(Magic Method)简明总结
Jul 08 #PHP
You might like
PHP 进程锁定问题分析研究
2009/11/24 PHP
PHP array操作10个小技巧分享
2011/06/23 PHP
PHP CURL CURLOPT参数说明(curl_setopt)
2013/09/30 PHP
php使用gd2绘制基本图形示例(直线、圆、正方形)
2017/02/15 PHP
Laravel多用户认证系统示例详解
2018/03/13 PHP
TP5框架实现签到功能的方法分析
2020/04/05 PHP
jQuery 插件 将this下的div轮番显示
2009/04/09 Javascript
js监听鼠标点击和键盘点击事件并自动跳转页面
2014/09/24 Javascript
Jquery实现地铁线路指示灯提示牌效果的方法
2015/03/02 Javascript
一波JavaScript日期判断脚本分享
2016/03/06 Javascript
AngularJS 输入验证详解及实例代码
2016/07/28 Javascript
微信小程序中做用户登录与登录态维护的实现详解
2017/05/17 Javascript
bootstrap multiselect 多选功能实现方法
2017/06/05 Javascript
vue2.x集成百度UEditor富文本编辑器的方法
2018/09/21 Javascript
JavaScript 中 JSON.parse 函数 和 JSON.stringify 函数
2018/12/05 Javascript
vue router导航守卫(router.beforeEach())的使用详解
2019/04/19 Javascript
深入浅析vue-cli@3.0 使用及配置说明
2019/05/08 Javascript
vue+element搭建后台小总结 el-dropdown下拉功能
2020/04/10 Javascript
js实现飞机大战游戏
2020/08/26 Javascript
python连接mongodb操作数据示例(mongodb数据库配置类)
2013/12/31 Python
Python实现excel转sqlite的方法
2017/07/17 Python
用python简单实现mysql数据同步到ElasticSearch的教程
2018/05/30 Python
Python 带有参数的装饰器实例代码详解
2018/12/06 Python
python PIL/cv2/base64相互转换实例
2020/01/09 Python
Python 通过监听端口实现唯一脚本运行方式
2020/05/05 Python
open_basedir restriction in effect. 原因与解决方法
2021/03/14 PHP
无畏的旅行:Intrepid Travel
2017/12/20 全球购物
周仰杰(JIMMY CHOO)法国官方网站:闻名世界的鞋子品牌
2019/09/27 全球购物
应届生高等护理求职信
2013/10/12 职场文书
简历中个人自我评价范文
2013/12/26 职场文书
幼儿园庆六一活动方案
2014/03/06 职场文书
大专毕业生求职信
2014/07/05 职场文书
机械机修工岗位职责
2014/08/03 职场文书
中秋节晚会开场白
2015/05/29 职场文书
python 爬取华为应用市场评论
2021/05/29 Python
springboot layui hutool Excel导入的实现
2022/03/31 Java/Android