strtotime unexpected result with white space #19803
Description
Activity
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.
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):while (isspace((unsigned char)*s) && s <= e) { s++; }
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):while (isspace((unsigned char)*s) && s < e) { s++; }
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!
Description
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.
The following code:
Resulted in this output:
But I expected this output instead:
PHP Version
Operating System
No response