|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2012-01-04 14:20 UTC] derick@php.net
-Status: Open
+Status: Bogus
[2012-01-04 14:20 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 13:00:01 2025 UTC |
Description: ------------ DateTime validation is incomplete. According to DateTime::__construct documentation this is not a bug: // Non-existent values roll over. $date = new DateTime('2000-02-30'); echo $date->format('Y-m-d H:i:sP') . "\n"; I disagree. There should be at least some way to require a proper validation (such as checkdate() function provides) for input dates. If you think this is incorrect behavior and rolling over is the desired one, then please implement the rolling so that one can for example give "2000-02-37" as the argument. Now DateTime checks the day of the month like this: 0 <= x <= 31. Test script: --------------- <?php $date = new DateTime('2011-02-31'); print $date->format('Y-m-d'); $date = new DateTime('2011-02-32'); print $date->format('Y-m-d'); ?> Expected result: ---------------- Both DateTime constructors should throw an Exception describing that the date is invalid. Actual result: -------------- Now the constructor with '2011-02-32' as its parameter is the only one throwing Exception about invalid date.