|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2020-01-27 17:44 UTC] h dot kocznar at compunect dot com
Description: ------------ --- From manual page: https://php.net/datetime.createfromformat --- $foo = \DateTime::createFromFormat('U.u', \microtime(true)); This is affecting a huge amount of PHP projects, the function will fail with an error when microtime returns a float without precision values which happens when the time is exactly on that second. This problem was reported 7 years ago and the developer in charge declared the error as "not a bug" because microtime() produces "garbage". Due to the lack of professionalism on his behalf the error is still present in PHP 7.3 PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 00:00:02 2025 UTC |
To clarify: passing the return value of microtime(true) directly to DateTime::createFromFormat() using a 'U.u' is generally not supposed to work. Not only if microtime(true) returns a float without decimals, but also for many locales, e.g. php > var_dump(setlocale(LC_ALL, "de-DE")); string(5) "de-DE" php > var_dump(DateTime::createFromFormat('U.u', 1580204901.4929)); bool(false) Use number_format() or sprintf() with the F specifier for maximum portability.