|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80694 DateTime::createFromFormat not return false in all cases
Submitted: 2021-02-01 14:40 UTC Modified: 2021-09-01 13:16 UTC
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: 007not at gmail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 8.0.1 OS: Any
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: 007not at gmail dot com
New email:
PHP Version: OS:


 [2021-02-01 14:40 UTC] 007not at gmail dot com
In the current implementation, there is no explicit return type behaviour for the createfromformat method.
There 3 states:
* everything ok and createfromformat return object
* error, when createfromformat return false
* warning, return object but need do extra check with method getLastErrors

possible solutions:
* change behaviour for createfromformat in next release. make warnings as errors and return false if any warning happens
* change documentation. add information about getLastErrors method, add example for getLastErrors to page, fix Return Values description

Test script:

$datetime = \DateTimeImmutable::createFromFormat('m.d.Y', '23.06.2020');

var_dump($datetime === false); //Return Values: false on failure 
var_dump(\DateTimeImmutable::getLastErrors()); //The parsed date was invalid

$datetime = \DateTimeImmutable::createFromFormat('d.m.Y', '23.06.2020');

var_dump($datetime === false);


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-01 13:16 UTC]
ext/date is generally very liberal (e.g. that wrap around behavior
is also supported elsewhere), so we better stick with doc problem.
 [2021-09-01 13:16 UTC]
-Type: Feature/Change Request +Type: Documentation Problem
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Sep 22 03:03:36 2021 UTC