Doc #80694 [Opn->Csd]: DateTime::createFromFormat not return false in all cases

[email protected] Sat, 04 Jun 2022 16:53:33 +0000
Newsgroups php.doc.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=80694&edit=1

 ID:                 80694
 Updated by:         [email protected]
 Reported by:        007not at gmail dot com
 Summary:            DateTime::createFromFormat not return false in all
                     cases
-Status:             Open
+Status:             Closed
 Type:               Documentation Problem
 Package:            Date/time related
 Operating System:   Any
 PHP Version:        8.0.1
 Block user comment: N
 Private report:     N

 New Comment:

Automatic comment on behalf of derickr
Revision: https://github.com/php/doc-en/commit/0aba3ea811b994d1d4a3be3572a34f8a8325e55c
Log: Fixed bug #80694: DateTimeImmutable::createFromFormat not return false in all cases


Previous Comments:
------------------------------------------------------------------------
[2021-09-01 13:16:17] [email protected]

ext/date is generally very liberal (e.g. that wrap around behavior
is also supported elsewhere), so we better stick with doc problem.

------------------------------------------------------------------------
[2021-02-01 14:40:37] 007not at gmail dot com

Description:
------------
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 https://www.php.net/manual/en/datetime.createfromformat.php, fix Return Values description

Test script:
---------------
<?php
//https://3v4l.org/JqSuG

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

var_dump($datetime);
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);
var_dump($datetime === false);
var_dump(\DateTimeImmutable::getLastErrors());



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80694&edit=1