Edit report at https://bugs.php.net/bug.php?id=80694&edit=1
ID: 80694
Updated by: cmb@php.net
Reported by: 007not at gmail dot com
Summary: DateTime::createFromFormat not return false in all
cases
Status: Open
-Type: Feature/Change Request
+Type: Documentation Problem
Package: Date/time related
Operating System: Any
PHP Version: 8.0.1
Block user comment: N
Private report: N
New Comment:
ext/date is generally very liberal (e.g. that wrap around behavior
is also supported elsewhere), so we better stick with doc problem.
Previous Comments:
------------------------------------------------------------------------
[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