php中,error_reporting(E_ALL || ~E_NOTICE)是何意?

php中,error_reporting(E_ALL || ~E_NOTICE)是何意?

2014-03-18 00:05 哎我4  |  分类:PHP  |  浏览445次
error_reporting(E_ALL);//显示所有错误
error_reporting(E_ALL ^ E_NOTICE);//显示除去 E_NOTICE 之外的所有错误信息
这里可以理解
但是这个
error_reporting(E_ALL || ~E_NOTICE);

这里的 || 是逻辑或 ~ 是位运算非。那么这句话翻译成什么呢? 所有错误,或者非E_NOTICE错误都提示
这样岂不是|| ~E_NOTICE部分就意义了,等同于所有错误都提示嘛,在网上我也搜索到了这种说法,但是这段代码出自dede,install/index.php中,他也不至于写这么段多余的代码吧
望高人指点,这是何用意?
分享到:
2014-03-18 09:52 提问者采纳
我本人觉得error_reporting(E_ALL || ~E_NOTICE)和error_reporting(E_ALL)效果是一样的
都是显示所有错误,这个是dede 在开发阶段时为了显示所有错误用的。
用二进制说
E_ALL 是 1111111111111
E_NOTICE 是 0000000001000
~E_NOTICE是 1111111110111

定义和用法

error_reporting() 设置 PHP 的报错级别并返回当前级别。

语法

error_reporting(report_level)

如果参数 level 未指定,当前报错级别将被返回。下面几项是 level 可能的值:

常量描述
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)

例子

任意数目的以上选项都可以用“或”来连接(用 OR 或 |),这样可以报告所有需要的各级别错误。例如,下面的代码关闭了用户自定义的错误和警告,执行了某些操作,然后恢复到原始的报错级别:

<?php
//禁用错误报告
error_reporting(0);

//报告运行时错误
error_reporting(E_ERROR | E_WARNING | E_PARSE);

//报告所有错误
error_reporting(E_ALL);
?>
举例说明: 

在Windows环境下:原本在php4.3.0中运行正常的程序,在4.3.1中为何多处报错,大体提示为:Notice:Undefined varialbe:变量名称. 
例如有如下的代码: 
复制代码代码如下:

if (!$tmp_i) { 
$tmp_i=10; 


在4.3.0中运行正常,在4.3.1中运行会提示Notice:Undefined varialbe:tmp_i 
问题下下: 
1.问题出在哪里? 
2.应如何修改这段代码? 
3.不改段代码,如何修改php.ini中的设置使原来在4.3.0中的程序在4.3.1的环境下运行正常?而不出现这个错误提示. 

解决办法: 

在程序开头加一句: 
error_reporting(E_ALL & ~E_NOTICE); 或error_reporting(E_ALL ^ E_NOTICE); 

或者 
修改php.ini 
error_reporting = E_ALL & ~E_NOTICE 


有关error_reporting()函数: 


error_reporting() 设置 PHP 的报错级别并返回当前级别。 

; 错误报告是按位的。或者将数字加起来得到想要的错误报告等级。 
; E_ALL - 所有的错误和警告 
; E_ERROR - 致命性运行时错 
; E_WARNING - 运行时警告(非致命性错) 
; E_PARSE - 编译时解析错误 
; E_NOTICE - 运行时提醒(这些经常是是你的代码的bug引起的, 

;也可能是有意的行为造成的。(如:基于未初始化的变量自动初始化为一个 
              ;空字符串的事实而使用一个未初始化的变量) 

; E_CORE_ERROR - 发生于PHP启动时初始化过程中的致命错误 
; E_CORE_WARNING - 发生于PHP启动时初始化过程中的警告(非致命性错) 
; E_COMPILE_ERROR - 编译时致命性错 
; E_COMPILE_WARNING - 编译时警告(非致命性错) 
; E_USER_ERROR - 用户产生的出错消息 
; E_USER_WARNING - 用户产生的警告消息 
; E_USER_NOTICE - 用户产生的提醒消息 

使用方法: 

error_reporting(0);//禁用错误报告 
error_reporting(E_ALL ^ E_NOTICE);//显示除去 E_NOTICE 之外的所有错误信息 
error_reporting(E_ALL^E_WARNING^E_NOTICE);//显示除去E_WARNING E_NOTICE 之外的所有错误信息 
error_reporting(E_ERROR | E_WARNING | E_PARSE);//显示运行时错误,与error_reporting(E_ALL ^ E_NOTICE);效果相同。error_reporting(E_ALL);//显示所有错误
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

北方的刀郎

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值