PHP 8.0 更改了松散比较的工作方式

PHP 8.0 changes how loose comparison works

让我们有一个简单的 PHP 脚本

<?php
var_dump("php" == 0);

根据官方文档 (https://www.php.net/manual/en/types.comparisons.php) , 这应该计算成 true

但是 它确实如此,对于 PHP <=7.4,但对于 PHP 8.0

则没有

在 PHP 8 (8.0.0 - 8.0.2) 的当前版本中,它评估为 false

此功能是否有任何未记录的更改,或者这是一个错误?还是我遗漏了什么?

谢谢

当PHP 8 被释放时,他们还放了一个release announcement on the website. This is part of one of the new major changes, the saner string to number comparison

引用:

When comparing to a numeric string, PHP 8 uses a number comparison. Otherwise, it converts the number to a string and uses a string comparison.

此行为记录在 Backward incompatible changes

String to Number Comparison

Non-strict comparisons between numbers and non-numeric strings now work by casting the number to string and comparing the strings. Comparisons between numbers and numeric strings continue to work as before. Notably, this means that 0 == "not-a-number" is considered false now.

PHP 此处的文档维护者,PHP 8 确实更改了语义,这显示在迁移指南中。然而,文档的其他部分仍然落后,因为我们没有 manpower/time 来编辑和记录与 PHP 8.

相关的所有更改

所以这不是一个错误,更多的是当前类型杂耍页面对于 PHP 8.0 已经过时了。

可以通过对 GitHub 存储库的合并请求为文档做出贡献。