php.net |  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
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: 007not at gmail dot com Assigned:
Status: Closed Package: Date/time related
PHP Version: 8.0.1 OS: Any
Private report: No CVE-ID: None
 [2021-02-01 14:40 UTC] 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());


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-09-01 13:16 UTC] cmb@php.net
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] cmb@php.net
-Type: Feature/Change Request +Type: Documentation Problem
 [2022-06-04 16:53 UTC] git@php.net
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
 [2022-06-04 16:53 UTC] git@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 10:01:30 2024 UTC