error_reporting(E_ALL) 和 error_reporting(E_ALL & ~E_NOTICE) 之间有什么区别

发布于 2024-08-10 17:51:49 字数 198 浏览 3 评论 0原文

谁能解释 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

我不是你的备胎 2024-08-17 17:51:49

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)

残月升风 2024-08-17 17:51:49

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.

月依秋水 2024-08-17 17:51:49

E_ALL 是一个标志
E_NOTICE 也是一个标志,

因此当您对 ~ 执行按位操作(这不是 NOT)时,您将从 E_ALL 中排除 E_NOTICE

在幕后,以下发生

在十进制中

E_ALL = 32767 
E_NOTICE = 8

的 2

按位

E_ALL    = 111111111111111
E_NOTICE = 000000000001000

,它们是NOT

111111111110111

结果的幂,然后 php 可以在内部检查通知是否为ON 使用 &(AND) 运算符

111111111110111
000000000001000

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

E_ALL = 32767 
E_NOTICE = 8

they are power of 2

bitwise

E_ALL    = 111111111111111
E_NOTICE = 000000000001000

result of NOT will be

111111111110111

then php can internally check if notices are ON with &(AND) operator

111111111110111
000000000001000

1 & 0 = 0 it means it is turned off. If however you didn't use ~ NOT then it would be 1 & 1 = 1 it means that flag is SET

There 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文