error_reporting(E_ALL) 和 error_reporting(E_ALL & ~E_NOTICE) 之间有什么区别
谁能解释 error_reporting(E_ALL);
和 error_reporting(E_ALL & ~E_NOTICE);
之间的区别?
我注意到,当我从 E_ALL
更改为 E_ALL & ~E_NOTICE
,我正在破解的错误消失了。
Could anyone explain differences between error_reporting(E_ALL);
and error_reporting(E_ALL & ~E_NOTICE);
?
I noticed that when I change from E_ALL
to E_ALL & ~E_NOTICE
, an error which I was hacking, disappears.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
E_ALL 是“一切”
E_ALL & ~E_NOTICE 是“除通知之外的所有内容”
通知是最不紧急的消息类型。但它们对于捕获愚蠢的程序员错误非常有用,例如尝试从具有不存在的键的散列中读取等。
(要理解语法,请阅读按位运算符)
E_ALL is "everything"
E_ALL & ~E_NOTICE is "everything except notices"
Notices are the least-urgent kinds of messages. But they can be very useful for catching stupid programmer mistakes, like trying to read from a hash with a non-existent key, etc.
(To understand the syntax, read up on bitwise operators)
E_ALL 应该包含所有错误、警告和通知 - 所有内容
E_NOTICE 是一个特殊的错误级别,显示不会产生错误但不好或将在未来的 PHP 版本中过时的内容。通知错误级别旨在鼓励最佳实践。
另外,它应该是
error_reporting(E_ALL ^ E_NOTICE);
来报告除通知之外的所有内容。建议您在开发过程中将错误报告设置为E_ALL并修复所有通知错误。
查看手册会提供更多详细信息。
E_ALL would should all the error and warning and notice - everything
E_NOTICE is a special error level, showing things that won't produce error but are not good or gonna be obsolete in future release of PHP. The notice error level is meant to encourage best practices.
Also it should be
error_reporting(E_ALL ^ E_NOTICE);
to report everything except notice.You are advice during development to set the error reporting to E_ALL and fix all the notice errors.
a look in the manual would give much more details.
E_ALL 是一个标志
E_NOTICE 也是一个标志,
因此当您对 ~ 执行按位操作(这不是 NOT)时,您将从 E_ALL 中排除 E_NOTICE
在幕后,以下发生
在十进制中
的 2
按位
,它们是NOT
结果的幂,然后 php 可以在内部检查通知是否为ON 使用 &(AND) 运算符
1 & 0 = 0
表示已关闭。但是,如果您没有使用 ~ NOT 那么它将是1 & 1 = 1
表示标志已设置。还有其他选项,例如 OR 打开标志,或 XOR 将标志更改为相反状态。基本上,这就是标志的工作原理。
E_ALL is a flag
E_NOTICE is a flag as well
so when you do bitwise operation of ~ which is NOT you'll exclude E_NOTICE from E_ALL
Under the hood following happens
in decimal
they are power of 2
bitwise
result of NOT will be
then php can internally check if notices are ON with &(AND) operator
1 & 0 = 0
it means it is turned off. If however you didn't use ~ NOT then it would be1 & 1 = 1
it means that flag is SETThere are other options for example OR to turn on the flag, or XOR to change the flag to opposite state. Basically, this is how flags work.