Bug #75249 [Com]: datetime constructor does not throws exception on invalida date

From: Date: Sat, 23 Sep 2017 14:51:37 +0000
Subject: Bug #75249 [Com]: datetime constructor does not throws exception on invalida date
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-211332@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75249&edit=1 ID: 75249 Comment by: contatto at developiu dot it Reported by: contatto at developiu dot it Summary: datetime constructor does not throws exception on invalida date Status: Not a bug Type: Bug Package: Date/time related Operating System: linux PHP Version: 7.1.9 Block user comment: N Private report: N New Comment: requinix, you are right: it is in the documentation too (Example #2 Intricacies of DateTime::__construct()). So it is neither a datetime problem nor a documentation problem. Thank you for your comment: I think we can close it. have a nice day Francesco Previous Comments: ------------------------------------------------------------------------ [2017-09-23 14:41:23] requinix@php.net If the *format* is invalid. Your example uses the perfectly acceptable YYYY-MM-DD format - the DD value being too high for the given month is something else. If you want to know whether the date itself was invalid then you can use getLastErrors(): https://3v4l.org/SIEmX ------------------------------------------------------------------------ [2017-09-23 14:20:53] contatto at developiu dot it Description: ------------ In the ducumentation it is stated that from php 5.3 if time contains an invalid date/time format, then an exception is now thrown. Previously an error was emitted. This does not happen always, as the code below shows. No exception is thrown and the date object is the first of march. Note: I'm using php from remi repositories and php --version shows version 7.1.7 which is not an available options in the select before. Test script: --------------- $d=new DateTime("2017-02-29"); var_dump($d); ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=75249&edit=1

« previous php.bugs (#211332) next »