php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #80694 DateTime::createFromFormat not return false in all cases
Submitted: 2021-02-01 14:40 UTC Modified: -
Votes:1
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Apr 19 13:01:25 2021 UTC