You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
strtotime unexpected result with white space #19803
Passing white space to strtotime() gives the current time. I assume it's parsing it as an empty date (which means now) + and empty modifier (which means nothing), so now + 0 = now.
But it seems like it should (?) return false if the date and modifier are both empty.
While checking the PHP 8.5.11 source, I noticed that the fix from timelib commit f2420f2 appears to be present in ext/date/lib/parse_date.re, but not in the generated ext/date/lib/parse_date.c.
It looks like the fix for the issue @masakuuuu noted became effective in PHP 8.4.27
I reproduced the behavior with whitespace-only input using PHP 8.4.26 and 8.4.27:
PHP 8.4.26: strtotime() and DateTime still accept the whitespace-only value.
PHP 8.4.27: strtotime() returns false and DateTime throws a DateMalformedStringException with Empty string.
We encountered this behavior change after upgrading to PHP 8.4.27.
Could you please confirm?
If so, it might be worth clarifying the release notes: they currently list this issue as fixed in PHP 8.4.24, while the old behavior was still present in PHP 8.4.26 and there is no corresponding Date entry for PHP 8.4.27 for what I see.
Same applies for the 8.5 versions.
Activity
derickr commentedon Feb 4, 2026
This was indeed a bug, but it was in the library providing the date time support. I have fixed it there now: derickr/timelib@f2420f2
Once there are more pressing changes, I will merge these into PHP as well.
masakuuuu commentedon Oct 10, 2026
Thanks for fixing this in timelib.
While checking the PHP 8.5.11 source, I noticed that the fix from timelib commit f2420f2 appears to be present in
ext/date/lib/parse_date.re, but not in the generatedext/date/lib/parse_date.c.Commit: derickr/timelib@f2420f2
Source comparison
In
parse_date.re(line 1901):Source: https://github.com/php/php-src/blob/php-8.5.11/ext/date/lib/parse_date.re#L1901
However, in
parse_date.c(line 24773):Source: https://github.com/php/php-src/blob/php-8.5.11/ext/date/lib/parse_date.c#L24773
Since PHP compiles
parse_date.c, this discrepancy appears to mean that the fix may not be included in builds using the PHP 8.5.11 release source.Could you confirm whether
parse_date.cshould be regenerated and updated?I may be missing something, but I wanted to bring this discrepancy to your attention.
Thanks!
lukadefluiter commentedon Oct 22, 2026
It looks like the fix for the issue @masakuuuu noted became effective in PHP 8.4.27
I reproduced the behavior with whitespace-only input using PHP 8.4.26 and 8.4.27:
strtotime()andDateTimestill accept the whitespace-only value.strtotime()returnsfalseandDateTimethrows aDateMalformedStringExceptionwithEmpty string.We encountered this behavior change after upgrading to PHP 8.4.27.
Could you please confirm?
If so, it might be worth clarifying the release notes: they currently list this issue as fixed in PHP 8.4.24, while the old behavior was still present in PHP 8.4.26 and there is no corresponding Date entry for PHP 8.4.27 for what I see.
Same applies for the 8.5 versions.