|  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
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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: php at christian-stuedemann dot de
New email:
PHP Version: OS:


 [2015-04-21 13:18 UTC] php at christian-stuedemann dot de
From manual page:

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';


Add a Patch

Pull Requests

Add a Pull Request


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.
 [2015-06-02 17:36 UTC]
-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]
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.

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]
-Status: Open +Status: Wont fix
 [2015-06-02 18:02 UTC]
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 Feb 29 22:01:29 2024 UTC