Skip to content

strtotime unexpected result with white space #19803

Description

@Paxtez

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:

<?php
$date = ' ';
$utc = strtotime($date);
var_dump($date);
var_dump($utc);
?>

Resulted in this output:

string(1) " "
int(1757608141)

But I expected this output instead:

string(1) " "
bool(false)

PHP Version

8.2.20

Operating System

No response

Activity

  1. derickr commented on Feb 4, 2026

    @derickr
    Member

    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.

  2. masakuuuu commented on Oct 10, 2026

    @masakuuuu

    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 generated ext/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.c should be regenerated and updated?

    I may be missing something, but I wanted to bring this discrepancy to your attention.

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions