英文:
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)).
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论