• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

PHP报错级别设置和原理分析

php 搞代码 4年前 (2022-01-22) 21次浏览 已收录 0个评论

这篇文章主要介绍了关于PHP报错级别设置和原理分析 ,有着一定的参考价值,现在分享给大家,有需要的朋友可以参考一下

原理简介

在PHP配置文件中php.ini有如下配置:

; Error Level Constants:; E_ALL             - All errors and warnings (includes E_STRICT as of PHP 5.4.0); E_ERROR           - fatal run-time errors; E_RECOVERABLE_ERROR  - almost fatal run-time errors; E_WARNING         - run-time warnings (non-fatal errors); E_PARSE           - compile-time parse errors; E_NOTICE          - run-time notices (these are warnings which often result;                     from a bug in your code, but it's possible that it was;                     intentional (e.g., using an uninitialized variable and;                     relying on the fact it is automatically initialized to an;                     empty string); E_STRICT          - run-time notices, enable to have PHP suggest changes;                     to your code which will ensure the best interoperability;                     and forward compatibility of your code; E_CORE_ERROR      - fatal errors that occur during PHP's initial startup; E_CORE_WARNING    - warnings (non-fatal errors) that occur during PHP's;                     initial startup; E_COMPILE_ERROR   - fatal compile-time errors; E_COMPILE_WARNING - compile-time warnings (non-fatal errors); E_USER_ERROR      - user-generated error message; E_USER_WARNING    - user-generated warning message; E_USER_NOTICE     - user-generated notice message; E_DEPRECATED      - warn about code that will not work in future versions;                     of PHP; E_USER_DEPRECATED - user-generated deprecation warnings;; Common Values:;   E_ALL (Show all errors, warnings and notices including coding standards.);   E_ALL & ~E_NOTICE  (Show all errors, except for notices);   E_ALL & ~E_NOTICE & ~E_STRICT  (Show all errors, except for notices and coding standards warnings.);   E_COMPILE_ERROR|E_RECOVERABLE_ERROR|E_ERROR|E_CORE_ERROR  (Show only errors); Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED; <span style="color:transparent">本文来源gaodai#ma#com搞*!代#%^码$网!</span><strong>搞代gaodaima码</strong>Development Value: E_ALL; Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT; http://php.net/error-reportingerror_reporting = E_ALL

上面配置中:error_reporting为设置配置级别;默认是E_ALL,意思显示所有Notice,Warning,Error信息(Show all errors, warnings and notices including coding standards.)。
在PHP手册预定义常量中有详细解释,下面为摘录的一部分:

例子:E_ALL & ~E_NOTICE
E_ALL: 111011111111111
E_NOTICE: 1000
~E_NOTICE: 0111
E_ALL & ~E_NOTICE:111011111110111

php就是这样通过二进制的转换来控制错误级别的。

调整错误级别

全局设置

更改php.ini文件中的error_reporting就可以达到效果。
例如:

1. error_reporting = E_ALL #输出所有错误,警告,notice信息2. error_reporting = E_ALL & ~E_NOTICE #输出所有错误和警告信息,不输出notice信息3. E_ALL & ~E_NOTICE & ~E_WARNING #输出所有错误信息,不输出警告,notice信息

局部设置

在脚本或程序中,通过ini_set()和error_reporting()设置可以达到效果。
例如:

ini_set("display_errors",1)error_reporting(E_ALL)

相关推荐:

PHP报错并自动跳转

开发模式与产品模式下的PHP报错处理

以上就是PHP报错级别设置和原理分析 的详细内容,更多请关注搞代码gaodaima其它相关文章!


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:PHP报错级别设置和原理分析

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址