|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #61311 provide a way to enable exceptions for all warning in DateTime class
Submitted: 2012-03-07 05:28 UTC Modified: 2021-07-26 18:33 UTC
Avg. Score:5.0 ± 0.0
Reproduced:6 of 6 (100.0%)
Same Version:3 (50.0%)
Same OS:3 (50.0%)
From: icedglow at email dot it Assigned: cmb (profile)
Status: Wont fix Package: Date/time related
PHP Version: 5.4.0 OS: any
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-03-07 05:28 UTC] icedglow at email dot it

$a = DateTime::createFromFormat("H:i", "1:1");

doesn't create the istance because minutes part require two digits

but this code doesn't produce a php warning or notice, even an exception, none at 

it returns false, but it is a constructor...

so why I need to use the if(), when I'm in a try{} block?

I was thinking that php's new way was "converting to OOP".


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-29 21:44 UTC] kavi at postpro dot net
The statement in the example 'works' in 5.3.3.

Here's what I'm using in my unit test for the presence of this bug:

$a = DateTime::createFromFormat('H:i:s', 'asdf');  // should throw Exception

The statement actually returns false and does not throw an exception.
 [2021-07-26 18:33 UTC]
-Status: Open +Status: Wont fix -Assigned To: +Assigned To: cmb
 [2021-07-26 18:33 UTC]
So you actually prefer to write

    try {
        $a = DateTime::createFromFormat("H:i", "1:1");
    } catch (DateTimeException $ex) {
        // handle failure

instead of

    if (($a = DateTime::createFromFormat("H:i", "1:1")) === false) {
        // handle failure

I don't.  Feel free to pursue the RFC process[1], though. :)

[1] <>
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Sat Dec 09 13:01:27 2023 UTC