Bug #74482 [Opn]: Missing validation of date in DateTime::createFromFormat
| From: | spam at bugyik dot cz | Date: | Thu, 20 Apr 2017 16:24:29 +0000 |
| Subject: | Bug #74482 [Opn]: Missing validation of date in DateTime::createFromFormat | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-208692@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74482&edit=1
ID: 74482
User updated by: spam at bugyik dot cz
Reported by: spam at bugyik dot cz
Summary: Missing validation of date in
DateTime::createFromFormat
Status: Open
Type: Bug
Package: Date/time related
Operating System: Linux
PHP Version: 7.1.4
Block user comment: N
Private report: N
New Comment:
@allenjb: thanks for your suggestion, but I think this is only workaround, do you agree?
Previous Comments:
------------------------------------------------------------------------
[2017-04-20 15:06:17] php-bugs at allenjb dot me dot uk
DateTime has an internal warnings system it uses which you can use to detect invalid dates - see
DateTime::getLastErrors(): https://3v4l.org/8IBbL
------------------------------------------------------------------------
[2017-04-20 15:01:32] spam at bugyik dot cz
Description:
------------
I'm missing validation of date-time in DateTime::createFromFormat. The example below tells
more.
Test script:
---------------
<?php
var_dump(\DateTime::createFromFormat(\DateTime::RFC3339, '2017-99-99T08:51:13-03:00'));
Expected result:
----------------
some exception expected (like from new DateTime('bad-time'))
Actual result:
--------------
object(DateTime)#1 (3) {
["date"]=>
string(26) "2025-06-07 08:51:13.000000"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "-03:00"
}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74482&edit=1