我一直将一些过时的PHP代码迁移到PHP 8.1,并注意到,由于PHP 8.0某些内置功能现在会抛出TypeError异常,而不是当未正确键入参数时,而不是仅仅警告。 请参阅此处。
我似乎无法感到困惑找到对此变化的全面描述。我运行的代码检查工具也没有捕获,但我也不能怪它们,因为这可能是一个运行时问题。一些消息来源报告说,所有内置功能都被提升为投掷TypeErrors,其他消息来源说,只有某些功能受到影响。我已经搜索了一般的PHP ChangElog中的此更改,并且只能找到两个受影响的功能,这些功能是 array_column() and ,后者偶然是我在迁移的代码库中意识到这个问题的人。这是否意味着只有这两个功能受到变化的影响?
如果有人能够对此提供一些清晰度,我将非常感激。
I've been migrating some outdated PHP code to PHP 8.1 and noticed that since PHP 8.0 certain built-in functions will now throw a TypeError exception instead of a mere warning when the arguments passed aren't correctly typed. See here.
I'm quite baffled by the fact I can't seem to find a comprehensive description of this change. The code inspection tools I've ran didn't catch it either, but I can't blame them either, as this is likely a runtime issue. Some sources report all built-in functions have been promoted to throwing TypeErrors, other sources say only some functions are affected. I've already searched through the general PHP changelog for this change and was only able to locate two affected functions, those being array_column() and count(), the latter coincidentally being the one that made me aware of this issue in the codebase I'm migrating. Does this mean only these two functions are affected by the change?
If anyone is able to offer some clarity on this I'd be very grateful.
发布评论
评论(2)
此更改是由RFC https://wiki.php.net/rfc/rfc/consistent/consistent_type_errors 。
所有更改都在这里 https://github.com/php/php/php/php/php-src/拉/3794/文件
您可以在上面的PR上写下解析器以获取功能列表。
This change was made by RFC https://wiki.php.net/rfc/consistent_type_errors.
All changes is here https://github.com/php/php-src/pull/3794/files
You can write a parser over PR above to get a list of functions.
许多功能已从/等于8.0版本更改。主要是,从一些简单的功能中删除了null支持参数。例如,在 str_replace 中, preg_replace 第二个参数不能为 null 值。要迁移PHP的最后一个版本,您可以观看PHP版本的一致性,并从这里查看贬值。
PHP版本8 有向后不相容的变化
https://www.php.net/manual/manual/en/en/en/migration80.compatible。 php
您可以看到所有列表新附录
确切地说,关于您的错误(count(count()函数),您可以从此处阅读: https:// github.com/aisingapore/tagui/issues/1137
关于上一个版本的特定PHP类型错误,您可以阅读:
https://php.watch/versions/8.0/8.0/internal-function-expceptions-exceptions-exceptions-exceptions-exceptions-exceptions-exceptions-exceptions-exceptions-exceptions-exceptions-exceptions-exceptions
这里指出的一些迁移信息:
5.6⇾7.0
7.3⇾7.4 https://www.php.net/manual/en/en/migration74.php
7.4⇾8.0 https://www.php.net/manual/enual/en/migration80.php
Many functions have changed from/equal 8.0 version. Mainly, from some simple functions, deleted null supporting argument. For example, in str_replace, preg_replace second argument can not be NULL value already. To migrate last version of PHP, you can watch consistency of PHP version, and to look from here how deprecation were.
There are backward Incompatible Changes for PHP version 8
https://www.php.net/manual/en/migration80.incompatible.php
You can see all list new appendices
https://www.php.net/manual/en/appendices.php
Exactly, about your error (count() function) you can read from here: https://github.com/aisingapore/TagUI/issues/1137
About last version's specific PHP Type errors, you can read:
https://php.watch/versions/8.0/internal-function-exceptions
Some migration information noted here:
5.6 ⇾ 7.0 https://www.php.net/manual/en/migration70.php
7.3 ⇾ 7.4https://www.php.net/manual/en/migration74.php
7.4 ⇾ 8.0 https://www.php.net/manual/en/migration80.php