E_ALL 的意义何在? E_STRICT 是否与 E_ALL 相同?

发布于 2024-08-09 00:56:39 字数 467 浏览 3 评论 0原文

  • E_ALL 等于 8191 (0001 1111 1111 1111)
  • E_STRICT 等于 2048 (0000 1000 0000 0000)

使用按位或将它们结合起来:

1 1111 1111 1111
  1000 0000 0000

我们得到与原始 E_ALL完全相同相同的值:

1 1111 1111 1111

如果我们可以简单地实现,那么执行 error_reporting(E_ALL | E_STRICT) 有什么意义执行 error_reporting(E_ALL) 得到同样的结果?

  • E_ALL equals 8191 (0001 1111 1111 1111)
  • E_STRICT equals 2048 (0000 1000 0000 0000)

Using bitwise OR to combine them:

1 1111 1111 1111
  1000 0000 0000

We get the exact same value as the original E_ALL:

1 1111 1111 1111

What's the point of doing error_reporting(E_ALL | E_STRICT) if we can simply do error_reporting(E_ALL) to get the same thing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

风尘浪孓 2024-08-16 00:56:39

您希望:

error_reporting(E_ALL | E_STRICT);

E_ALL 不包括 E_STRICT(除非您使用的是 PHP 5.4+)。你的价值观不正确。来自 预定义常量 E_ALL 定义为:

支持的所有错误和警告,
PHP 5.4 之前的 E_STRICT 级别除外。

PHP 5.4.x 中为 32767,PHP 5.3.x 中为 30719,
PHP 5.2.x 中为 6143,之前为 2047

You want:

error_reporting(E_ALL | E_STRICT);

E_ALL does not include E_STRICT (unless you are using PHP 5.4+). Your values are incorrect. From Predefined Constants E_ALL is defined as:

All errors and warnings, as supported,
except of level E_STRICT prior to PHP 5.4.

32767 in PHP 5.4.x, 30719 in PHP 5.3.x,
6143 in PHP 5.2.x, 2047 previously

鸩远一方 2024-08-16 00:56:39

来自 php.net:

传入值 -1 将显示所有可能的错误,即使在未来的 PHP 版本中添加了新的级别和常量。从 PHP 5.4 开始,E_ALL 常量也以这种方式运行。

from php.net:

Passing in the value -1 will show every possible error, even when new levels and constants are added in future PHP versions. The E_ALL constant also behaves this way as of PHP 5.4.

可遇━不可求 2024-08-16 00:56:39

问题中提供的位值通常不会错误,但仅适用于 5.4 之前的 PHP 版本。

PHP 5.4+

E_ALL 包含 E_STRICT,因此您应该使用:error_reporting(E_ALL);

Binary                  Name       Decimal
0001 1111 1111 1111     E_ALL      32767
0000 1000 0000 0000     E_STRICT   2048
----------------------------------------------------------------------
0001 1111 1111 1111     E_ALL | E_STRICT produces the same result as E_ALL

PHP 5.3

E_ALL 不包含E_STRICT 因此您应该使用:error_reporting(E_ALL | E_STRICT);

Binary                  Name       Decimal
0111 0111 1111 1111     E_ALL      30719
0000 1000 0000 0000     E_STRICT   2048
----------------------------------------------------------------------
0111 1111 1111 1111     E_ALL | E_STRICT produces a different value than E_ALL

PHP 5.0 至 5.2

E_ALL 不包括 E_STRICT因此您应该使用:error_reporting(E_ALL | E_STRICT);,但位值与 PHP 5.3 中的值不同。

5.0 之前的 PHP

E_STRICT 不存在,因此必须使用:error_reporting(E_ALL);

The bit values provided in the question are not generally wrong but only for PHP versions older than 5.4.

PHP 5.4+

E_ALL includes E_STRICT so you should use: error_reporting(E_ALL);

Binary                  Name       Decimal
0001 1111 1111 1111     E_ALL      32767
0000 1000 0000 0000     E_STRICT   2048
----------------------------------------------------------------------
0001 1111 1111 1111     E_ALL | E_STRICT produces the same result as E_ALL

PHP 5.3

E_ALL does not include E_STRICT so you should use: error_reporting(E_ALL | E_STRICT);

Binary                  Name       Decimal
0111 0111 1111 1111     E_ALL      30719
0000 1000 0000 0000     E_STRICT   2048
----------------------------------------------------------------------
0111 1111 1111 1111     E_ALL | E_STRICT produces a different value than E_ALL

PHP 5.0 till 5.2

E_ALL does not include E_STRICT so you should use: error_reporting(E_ALL | E_STRICT); but the bit values differ from the values in PHP 5.3.

PHP before 5.0

E_STRICT does not exist so you must use: error_reporting(E_ALL);

水中月 2024-08-16 00:56:39

1 | 1 = 1

最简单的答案可能是,目前没有理由将两者与按位或运算结合起来,但如果他们决定将来更改这些常量,那么可能会有。

编辑:您似乎为这些常量提取了错误的值,使整个问题变得毫无意义。

1 | 1 = 1

The simplest answer possible is that there's presently no reason to combine the two with a bitwise or operation, but if they ever decide to change those constants in the future, then there might be.

Edit: and you seem to have pulled the wrong values for those constants, making the entire question moot.

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