Bug #66201 [NEW]: DateTime::createFromFormat returns DateTime object although the date is invalid
| From: | ante dot drnasin at wirecard dot com | Date: | Fri, 29 Nov 2013 11:02:59 +0000 |
| Subject: | Bug #66201 [NEW]: DateTime::createFromFormat returns DateTime object although the date is invalid | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-183007@lists.php.net to get a copy of this message | ||
From: ante dot drnasin at wirecard dot com
Operating system: Win7 Pro x64
PHP version: 5.5.6
Package: Date/time related
Bug Type: Bug
Bug description:DateTime::createFromFormat returns DateTime object although the date is invalid
Description:
------------
As per manual DateTime::createFromFormat returns DateTime object or
false.
Test script:
---------------
$sDate = "25.27.2013"; //d.m.Y format
$mDateTime = DateTime::createFromFormat("d.m.Y", $sDate);
if($mDateTime instanceof DateTime) {
print("Date is ok!");
}
else {
print("Date not ok!");
}
var_dump($mDateTime);
var_dump(DateTime::getLastErrors());
Expected result:
----------------
Date not ok!
$mDateTime = false;
DateTime::getLastErrors() holds "The parsed date was invalid" message
Actual result:
--------------
Date is ok. (converted to 2015-03-25 10:57:26 which is weird but ok. can
swallow that although it doesn't make any sense to calculate a "real"
date from 25.27.2013 input to begin with)
$mDateTime is DateTime object
BUT!
DateTime::getLastErrors() is:
array(4) {
["warning_count"]=>
int(1)
["warnings"]=>
array(1) {
[10]=>
string(27) "The parsed date was invalid"
}
["error_count"]=>
int(0)
["errors"]=>
array(0) {
}
}
so there are erros in error array but the date is valid and is DateTime
object instead of false!?
--
Edit bug report at https://bugs.php.net/bug.php?id=66201&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66201&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66201&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66201&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66201&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66201&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66201&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66201&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66201&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66201&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66201&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66201&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66201&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66201&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66201&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66201&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66201&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66201&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66201&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66201&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66201&r=mysqlcfg