Req #61311 [Opn->Wfx]: provide a way to enable exceptions for all warning in DateTime class

From: Date: Mon, 26 Jul 2021 18:33:10 +0000
Subject: Req #61311 [Opn->Wfx]: provide a way to enable exceptions for all warning in DateTime class
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235376@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=61311&edit=1

 ID:                 61311
 Updated by:         cmb@php.net
 Reported by:        icedglow at email dot it
 Summary:            provide a way to enable exceptions for all warning
                     in DateTime class
-Status:             Open
+Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Date/time related
 Operating System:   any
 PHP Version:        5.4.0
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

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] <https://wiki.php.net/rfc/howto>


Previous Comments:
------------------------------------------------------------------------
[2012-05-29 21:44:15] 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.

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

Description:
------------
hello

$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 
all

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".



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=61311&edit=1


Thread (3 messages)

« previous php.bugs (#235376) next »