From: ostico at gmail dot com Operating system: Linux PHP version: Irrelevant Package: Class/Object related Bug Type: Feature/Change Request Bug description:DateTime::CreateFromFormat return false
Description: ------------ --- >From manual page: http://www.php.net/datetime.createfromformat#refsect1- datetime.createfromformat-returnvalues --- I think that returning false is a bad behaviour that lead to surely unwanted fatal exception when passing to it not well formatted dates. This static method seems to be thought to get a datetime object on which method format can be called inline: DateTime::CreateFromFormat()->format() But on not well formatted date strings the 'format' method raise an exception E_ERROR because it is called on a boolean. In my opinion CreateFromFormat should raise a throwable exception ( Best Solution ) or return an empty DateTime Object ( Unix Time 1970-01-01 ) and raise a warning, NOT a boolean value. Test script: --------------- php > var_dump( DateTime::CreateFromFormat('Y-m-d', '2013-05-') ); php > try { DateTime::CreateFromFormat('Y-m-d', '2013-05-'); } catch ( Exception $e ) { var_dump( 'ok' ); } php > try { var_dump( DateTime::CreateFromFormat('Y-m-d', '2013-05-')->format('dmY') ); } catch ( Exception $e ) { echo 'ok'; } Expected result: ---------------- PHP Warning: Uncaught exception 'Exception' in php shell code:1 string(2) "ok" string(2) "ok" //--------------- //alternatively the example should return an empty Datetime Object and raise a warning PHP Warning: Malformed Date String in php shell code on line 1 object(DateTime)#10 (3) { ["date"]=> string(19) "1970-01-01 00:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(13) "Europe/Berlin" } PHP Warning: Malformed Date String in php shell code on line 1 PHP Warning: Malformed Date String in php shell code on line 1 string(8) "01011970" Actual result: -------------- bool(false) PHP Fatal error: Call to a member function format() on a non-object in php shell code on line 1 -- Edit bug report at https://bugs.php.net/bug.php?id=64923&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=64923&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=64923&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=64923&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=64923&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=64923&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=64923&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=64923&r=needscript Try newer version: https://bugs.php.net/fix.php?id=64923&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=64923&r=support Expected behavior: https://bugs.php.net/fix.php?id=64923&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=64923&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=64923&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=64923&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=64923&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=64923&r=dst IIS Stability: https://bugs.php.net/fix.php?id=64923&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=64923&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=64923&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=64923&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=64923&r=mysqlcfg