PHP 8中对解析日期时间字符串进行了更改,但没有关于此的更改日志条目。

huangapple go评论54阅读模式
英文:

Changes have made to parsing date time strings in PHP 8 without changelog entries about it

问题

似乎在创建DateTime对象时,已经对日期时间字符串的解析方式进行了更改。

在PHP5和PHP7中,以下代码会导致错误,但在PHP8.2中,它将三位数字解释为年份后的天数,导致二月的第一天:

var_dump(new DateTime('2023-032'));

更糟糕的是,当给出类似以下的日期时间字符串时:

var_dump(new DateTime('2023-005-03'));

它会被解释为一月的第五天,并带有时区“-03:00”,而在之前的PHP版本中会抛出错误。

这些变更是在哪里进行的,为什么它们没有在变更日志中记录下来?

英文:

It seems that changes have been made how date time strings are parsed when creating DateTime objects.

Following code gives errors in PHP5 and PHP7, but for PHP8.2 it interprets the three digits after the year as number of days, resulting in the first of february:

var_dump(new DateTime('2023-032'));

Even worse: when given something like this:

var_dump(new DateTime('2023-005-03'));

it is interpreted as fifth of january with a timezone of "-03:00" whereas in previous PHP versions errors are thrown.

Where have those changes been made and why aren't they documented (as in changelogs)?

答案1

得分: 1

这将属于 https://www.php.net/ChangeLog-8.php#8.1.7

修复了 bug #51987(Datetime 无法解析 ISO 8601 序数日期(扩展格式))。

英文:

I suppose that would fall under https://www.php.net/ChangeLog-8.php#8.1.7,

> Fixed bug #51987 (Datetime fails to parse an ISO 8601 ordinal date (extended format)).

huangapple
  • 本文由 发表于 2023年6月9日 14:14:44
  • 转载请务必保留本文链接:https://go.coder-hub.com/76437662.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定