php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #69497 new DateTime('midnighty') should not be accepted
Submitted: 2015-04-21 13:18 UTC Modified: 2015-06-03 19:33 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: php at christian-stuedemann dot de Assigned:
Status: Wont fix Package: Date/time related
PHP Version: 5.6.8 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2015-04-21 13:18 UTC] php at christian-stuedemann dot de
Description:
------------
---
From manual page: http://www.php.net/datetime.construct
---

Even if it's a misspelling of the documented date format, an additional character added to the end of 'midnight' (e.g. 'midnighty' or 'midnighta') is accepted by the DateTime constructor. Longer terms (like 'midnightyyyy') are not accepted and throw an Exception like expected.

Test script:
---------------
try {
    new DateTime('midnighty');
    return 'this might never be returned, bug found';
}catch(Exception $e){
    return 'bug fixed';
}



Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-02 16:06 UTC] anikanov dot d at live dot ru
I have the same issue. I am think the problem in "re2c".
Generated file contain unnecessary lines like 23142 - 23144. 
https://github.com/php/php-src/blob/master/ext/date/lib/parse_date.c#L23142
 [2015-06-02 17:36 UTC] requinix@php.net
-Summary: new DateTime('midnighty') is accepted +Summary: new DateTime('midnighty') should not be accepted -Type: Bug +Type: Feature/Change Request
 [2015-06-02 17:36 UTC] requinix@php.net
The trailing letter is actually being interpreted as a timezone. The whole thing fits the general scheme of time + timezone so it's accepted: "midnighty" = "midnight" + "y" = 00:00:00 UTC-12.

http://3v4l.org/gDR6n
http://en.wikipedia.org/wiki/List_of_military_time_zones

Rather than close this, I'm turning it into a feature request that (eg,) keywords like "midnight" should stand alone and need some kind of word boundary afterwards. Bit of a BC break but I figure the current behavior too easy to mistake as a bug and I doubt it's used intentionally that often.
 [2015-06-02 18:02 UTC] derick@php.net
-Status: Open +Status: Wont fix
 [2015-06-02 18:02 UTC] derick@php.net
I don't think it's worth the BC breaks and it's really not a simple thing to do with the parser.
 [2015-06-03 19:33 UTC] php at christian-stuedemann dot de
I'd recommend to update the documentation accordingly at least, because this might be a hard to find trap, if this feature is unknown. Espc. because it changes the time stamp unexpectedly, thus it's not "midnight" any more.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 13:01:28 2024 UTC