|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2018-02-22 11:11 UTC] pmmaga@php.net
-Summary: DateTime::createFromString() does not work with years
> 4 digits
+Summary: DateTime::createFromFormat() does not work with years
> 4 digits
-Status: Open
+Status: Not a bug
[2018-02-22 11:11 UTC] pmmaga@php.net
[2018-02-22 14:22 UTC] dktapps at pmmp dot io
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 21:00:01 2025 UTC |
Description: ------------ DateTime formats can be created using format() which have >4 digits in the year, which cannot be parsed using createFromFormat() with the same format-string. As seen below the same format is used both times. This bug report looks absurd, but I've had similar issues been auto-reported to my crash archive when users put absurd values in configuration, and this appears to be why. Test script: --------------- <?php $datetime = new \DateTime('@' . PHP_INT_MAX); $str = $datetime->format("Y-m-d H:i:s O"); var_dump($str); //275808-11-04 10:06:43 +0000 var_dump(\DateTime::createFromFormat("Y-m-d H:i:s O", $str)); //bool(false) ?> Expected result: ---------------- Either: bool(false) bool(false) OR string(33) "292277026596-12-04 15:30:07 +0000 object(DateTime)#2 (3) { ["date"]=> string(34) "292277026596-12-04 15:30:07.000000 ["timezone_type"]=> int(1) ["timezone"]=> string(6) "+00:00" } Actual result: -------------- string(33) "292277026596-12-04 15:30:07 +0000" bool(false)