|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-03-17 10:59 UTC] martin dot contento at gmail dot com
Description: ------------ As i can not comment on http://bugs.php.net/bug.php?id=42971 I opened this new bug, i hope this is ok... The error here is that an invalid Date like this one should be caught in the DateTime's constructor, which then should return false as it claims in it's documentation (http://de2.php.net/manual/en/function.date-create.php) BTW: This specific string gains it's "importance" by the fact that it's the default mysql puts in a DATETIME field. Reproduce code: --------------- <?php error_reporting(E_ALL | E_NOTICE | E_STRICT); date_default_timezone_set('Europe/Berlin'); $buggy1 = '0000-00-00 00:00:00'; print "Creating DateTime with $buggy1\n"; $dt = new DateTime($buggy1); if ( ($buggy1 instanceof bool) and ($buggy1 === false)) { print "hooray, it correctly noticed the error\n"; } else { print "oh no, it did ... something...\n"; print "formated as Y-m-d H:i:s\n"; var_dump($dt->format('Y-m-d H:i:s')); print "formated as U\n"; var_dump($dt->format('U')); } ?> Expected result: ---------------- Creating DateTime with 0000-00-00 00:00:00 hooray, it correctly noticed the error Actual result: -------------- Creating DateTime with 0000-00-00 00:00:00 oh no, it did ... something... formated as Y-m-d H:i:s string(19) "1999-11-30 00:00:00" formated as U string(9) "943916400" PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 08 14:00:02 2025 UTC |
I'm very sorry, i mad a mistake when copying the code from my testfile, it should be like this (the if needs to check "$dt1" and not "$buggy1") Reproduce code: --------------- <?php error_reporting(E_ALL | E_NOTICE | E_STRICT); date_default_timezone_set('Europe/Berlin'); $buggy1 = '0000-00-00 00:00:00'; print "Creating DateTime with $buggy1\n"; $dt1 = new DateTime($buggy1); if ( ($dt1 instanceof bool) and ($dt1 === false)) { print "hooray, it correctly noticed the error\n"; } else { print "oh no, it did ... something...\n"; print "formated as Y-m-d H:i:s\n"; var_dump($dt1->format('Y-m-d H:i:s')); print "formated as U\n"; var_dump($dt1->format('U')); } ?>