|   | php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login | 
| 
  [2012-03-07 05:28 UTC] 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".
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits             | |||||||||||||||||||||||||||||||||||||
|  Copyright © 2001-2025 The PHP Group All rights reserved. | Last updated: Fri Oct 31 01:00:01 2025 UTC | 
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.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>