Edit report at https://bugs.php.net/bug.php?id=60650&edit=1
ID: 60650 Updated by: der...@php.net Reported by: ville dot salonen at iki dot fi Summary: DateTime validation is incomplete -Status: Open +Status: Bogus Type: Bug Package: Date/time related PHP Version: 5.3.8 Block user comment: N Private report: N New Comment: Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php Hi! The parser checks for possible day numbers (00-31) and the validation for validity. With date_get_last_errors() you can find the warnings: derick@whisky:~$ php <?php $date = new DateTime('2000-02-30'); echo $date->format('Y-m-d H:i:sP') . "\n"; var_dump(date_get_last_errors()); ?> 2000-03-01 00:00:00+00:00 array(4) { 'warning_count' => int(1) 'warnings' => array(1) { [11] => string(27) "The parsed date was invalid" } 'error_count' => int(0) 'errors' => array(0) { } } We can't really change this because of BC reasons. Previous Comments: ------------------------------------------------------------------------ [2012-01-04 10:15:11] ville dot salonen at iki dot fi 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. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=60650&edit=1