找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 215|回复: 0
打印 上一主题 下一主题

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

[复制链接]

2647

主题

2647

帖子

7881

积分

论坛元老

Rank: 8Rank: 8

积分
7881
跳转到指定楼层
楼主
发表于 2018-2-14 05:56:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式

            在PHP中所有的报错信息可以用error_reporting()这个函数来设置:
它的参数有字符串和数字两种表示方法,共14个等级,但是呢,我看使用其他数字貌似也可以,起初我以为它指的是一定的报错区间,后来,终于发现了其中的规律:
[U]复制代码[/U] 代码如下:error_reporting( 7 ) = error_reporting( 1+2+4)= error_reporting(E_ERROR | E_WARING | E_PARSE)
现在,我将其总结如下:
数字常量说明
1E_ERROR致命错误,脚本执行中断,就是脚本中有不可识别的东西出现
      举例: Error:Invalid parameters. Invalid parameter name
2E_WARNING部分代码出错,但不影响整体运行
      举例: Warning: require_once(E:/include/config_base.php)
4E_PARSE 字符、变量或结束的地方写规范有误
      举例:  Parse error: syntax error, unexpected $end in
8 E_NOTICE一般通知,如变量未定义等
      举例:  Notice: Undefined variable: p in E:\web\index.php on line 17
16 E_CORE_ERRORPHP进程在启动时,发生了致命性错误
      举例:  暂无
32 E_CORE_WARNING在PHP启动时警告(非致命性错误)
      举例:  暂无
64E_COMPILE_ERROR编译时致命性错误
      举例:  暂无
128E_COMPILE_WARNING编译时警告级错误
      举例:  暂无
256E_USER_ERROR 用户自定义的错误消息
      举例:  暂无
512E_USER_WARNING用户自定义的警告消息
      举例:  暂无
1024E_USER_NOTICE 用户自定义的提醒消息
      举例:  暂无
2047E_ALL以上所有的报错信息,但不包括E_STRICT的报错信息
      举例:  暂无
2048E_STRICT编码标准化警告,允许PHP建议如何修改代码以确保最佳的互操作性向前兼容性。

error_reporting 变量的默认值是  E_ALL & ~E_NOTICE
开发时,最佳的值为: E_ALL | E_STRICT
如果设置为:error_reporting(E_ALL | E_STRICT),则表示记录所有的错误信息
可能会导致网站出现一大堆的错误代码;但是对于程序员来说应该说是一件好事,可以把代码优化到最优; 一些非致命性错误虽然不影响程序的运行,但是会加重PHP的负担.
最后,晒出英文版的对照表:
1E_ERRORFatal run-time errors. Errors that can not be recovered from. Execution of the script is halted
2E_WARNINGNon-fatal run-time errors. Execution of the script is not halted
4E_PARSECompile-time parse errors. Parse errors should only be generated by the parser
8E_NOTICERun-time notices. The script found something that might be an error, but could also happen when running a script normally
16E_CORE_ERRORFatal errors at PHP startup. This is like an E_ERROR in the PHP core
32E_CORE_WARNINGNon-fatal errors at PHP startup. This is like an E_WARNING in the PHP core
64E_COMPILE_ERRORFatal compile-time errors. This is like an E_ERROR generated by the Zend Scripting Engine
128E_COMPILE_WARNINGNon-fatal compile-time errors. This is like an E_WARNING generated by the Zend Scripting Engine
256E_USER_ERRORFatal user-generated error. This is like an E_ERROR set by the programmer using the PHP function trigger_error()
512E_USER_WARNINGNon-fatal user-generated warning. This is like an E_WARNING set by the programmer using the PHP function trigger_error()
1024E_USER_NOTICEUser-generated notice. This is like an E_NOTICE set by the programmer using the PHP function trigger_error()
2048E_STRICTRun-time notices. PHP suggest changes to your code to help interoperability and compatibility of the code
4096E_RECOVERABLE_ERRORCatchable fatal error. This is like an E_ERROR but can be caught by a user defined handle (see also set_error_handler())
8191E_ALLAll errors and warnings, except level E_STRICT (E_STRICT will be part of E_ALL as of PHP 6.0)

            
            
您可能感兴趣的文章:
  • PHP函数之error_reporting(E_ALL ^ E_NOTICE)详细说明
  • PHP中error_reporting()函数的用法(修改PHP屏蔽错误)
  • PHP中error_reporting()用法详解
  • PHP中error_reporting函数用法详细介绍
            
  • 分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
    收藏收藏
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    用户反馈
    客户端