php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #72425 strtotime() should return false when string contains white space
Submitted: 2016-06-15 20:42 UTC Modified: 2022-05-13 14:05 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: alex at itc77 dot com Assigned: cmb (profile)
Status: Duplicate Package: Date/time related
PHP Version: 7.0.7 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: alex at itc77 dot com
New email:
PHP Version: OS:

 

 [2016-06-15 20:42 UTC] alex at itc77 dot com
Description:
------------
strtotime() doesn't return false when string contains white space

According to the documentation white space should be treated as invalid format and  return false.

Test script:
---------------
strtotime(" ")


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-06-15 20:44 UTC] alex at itc77 dot com
Please accept this patch:

https://github.com/php/php-src/pull/615
 [2016-06-16 11:34 UTC] cmb@php.net
I can confirm this behavior: <https://3v4l.org/HNaaY>.

> According to the documentation white space should be treated as
> invalid format and return false.

Where is this documented? That would actually be wrong; consider

  strtotime('2016-06-16 11:23')

which is supposed to be acceptable.
 [2016-06-16 22:46 UTC] mtanalin at yandex dot ru
To cmb@php.net:

Obviously, invalid should be whitespace-ONLY arguments (in other words, becoming empty string after `trim()`), not arguments _containing_ whitespace.

'2016-06-16 11:23' does not become an empty (zero-length) string after trimming whitespace.
 [2016-06-17 09:35 UTC] cmb@php.net
> Obviously, invalid should be whitespace-ONLY arguments (in other
> words, becoming empty string after `trim()`), not arguments
> _containing_ whitespace.

Indeed, thanks. However, where is this documented?
 [2016-06-21 22:10 UTC] mtanalin at yandex dot ru
To cmb@php.net:

It looks like just common sense that whitespace is not a valid date or time — because it’s not a date, it’s…, well, whitespace. ;-)

The “Date Formats” page [1] does not mention whitespace at all, the “Time Formats” page [2] lists space (`[ \t]`) as a possible value, but I’m not sure it is not about just a non-self-contained _token_ intended to be a part of a full valid date/time string containing _not_ just whitespace.

Anyway, interpreting whitespace as a current date looks confusing, so this behavior probably deserves changing.

[1] http://php.net/manual/en/datetime.formats.date.php
[2] http://php.net/manual/en/datetime.formats.time.php
 [2016-06-22 12:58 UTC] cmb@php.net
-Summary: strtotime() doesn't return false when string contains white space +Summary: strtotime() should return false when string contains white space -Type: Bug +Type: Feature/Change Request
 [2016-06-22 12:58 UTC] cmb@php.net
Thanks for pointing out the `space` time format. It does look like
to be intended to be a self-contained format, as several date
formats *contain* whitespace (for instance, `Textual month and
day`). And actually, that is quite contrary to what the reported
wrote.

> Anyway, interpreting whitespace as a current date looks
> confusing, so this behavior probably deserves changing.

I don't argue that accepting whitespace only as date time format
is rather doubtful, but as often is the case with *changes*, this
change would break BC. This is particularly bad, because the
whitespace has been documented to be allowed. So, in a strict
sense, this is not a bug. I'm changing to feature request.
 [2018-08-14 21:06 UTC] cmb@php.net
-Status: Open +Status: Duplicate -Type: Feature/Change Request +Type: Bug -Assigned To: +Assigned To: cmb
 [2018-08-14 21:06 UTC] cmb@php.net
Oops, disregard my former comment, since it is nonsense.

Anyhow, this is a duplicate of bug #66486.
 [2022-05-13 14:05 UTC] derick@php.net
I'm closing this (and the duplicate), as I am confused about this. Please open a new ticket at https://github.com/php/php-src/issues if this is still a pressing issue.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 18:01:29 2024 UTC