php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75249 datetime constructor does not throws exception on invalida date
Submitted: 2017-09-23 14:20 UTC Modified: 2017-09-23 14:41 UTC
From: contatto at developiu dot it Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 7.1.9 OS: linux
Private report: No CVE-ID: None
 [2017-09-23 14:20 UTC] 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);


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-23 14:41 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2017-09-23 14:41 UTC] 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:51 UTC] contatto at developiu dot it
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 10:01:28 2024 UTC