Req #80694 [NEW]: DateTime::createFromFormat not return false in all cases
| From: | 007not at gmail dot com | Date: | Mon, 01 Feb 2021 14:40:37 +0000 |
| Subject: | Req #80694 [NEW]: DateTime::createFromFormat not return false in all cases | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-231862@lists.php.net to get a copy of this message | ||
From: 007not at gmail dot com
Operating system: Any
PHP version: 8.0.1
Package: Date/time related
Bug Type: Feature/Change Request
Bug description:DateTime::createFromFormat not return false in all cases
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 bug report at https://bugs.php.net/bug.php?id=80694&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80694&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80694&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80694&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80694&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80694&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80694&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80694&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80694&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80694&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80694&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80694&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80694&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80694&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80694&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80694&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80694&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80694&r=mysqlcfg