phpphp-8.2

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


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)?


Solution

  • 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)).