3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function createDateFromFormat($format, $time) { $result = \DateTimeImmutable::createFromFormat($format, $time); var_dump(\DateTimeImmutable::getLastErrors()); return $result; } var_dump(\DateTimeImmutable::createFromFormat('Y-m-d', '2005-12-1')); var_dump(\DateTimeImmutable::createFromFormat('Y-m-d', '2005')); // should be false var_dump(\DateTimeImmutable::createFromFormat('Y-m-d', '0-0-0')); // should be false var_dump(createDateFromFormat('Y-m-d', '2005-12-1')); var_dump(createDateFromFormat('Y-m-d', '2005')); // should be false var_dump(createDateFromFormat('Y-m-d', '0-0-0')); // should be false
based on 99sTS
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.2.6
object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2005-12-01 16:27:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) object(DateTimeImmutable)#1 (3) { ["date"]=> string(27) "-0001-11-30 16:27:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } array(4) { ["warning_count"]=> int(0) ["warnings"]=> array(0) { } ["error_count"]=> int(0) ["errors"]=> array(0) { } } object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2005-12-01 16:27:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } array(4) { ["warning_count"]=> int(0) ["warnings"]=> array(0) { } ["error_count"]=> int(1) ["errors"]=> array(1) { [4]=> string(12) "Data missing" } } bool(false) array(4) { ["warning_count"]=> int(1) ["warnings"]=> array(1) { [5]=> string(27) "The parsed date was invalid" } ["error_count"]=> int(0) ["errors"]=> array(0) { } } object(DateTimeImmutable)#1 (3) { ["date"]=> string(27) "-0001-11-30 16:27:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" }
Output for hhvm-3.15.4
object(DateTimeImmutable)#1 (1) { ["data":"DateTimeImmutable":private]=> object(DateTime)#3 (3) { ["date"]=> string(26) "2005-12-01 16:27:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } bool(false) object(DateTimeImmutable)#3 (1) { ["data":"DateTimeImmutable":private]=> object(DateTime)#5 (3) { ["date"]=> string(27) "-0001-11-30 16:27:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } array(4) { ["warning_count"]=> int(0) ["warnings"]=> array(0) { } ["error_count"]=> int(0) ["errors"]=> array(0) { } } object(DateTimeImmutable)#5 (1) { ["data":"DateTimeImmutable":private]=> object(DateTime)#7 (3) { ["date"]=> string(26) "2005-12-01 16:27:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } array(4) { ["warning_count"]=> int(0) ["warnings"]=> array(0) { } ["error_count"]=> int(1) ["errors"]=> array(1) { [4]=> string(12) "Data missing" } } bool(false) array(4) { ["warning_count"]=> int(1) ["warnings"]=> array(1) { [5]=> string(27) "The parsed date was invalid" } ["error_count"]=> int(0) ["errors"]=> array(0) { } } object(DateTimeImmutable)#7 (1) { ["data":"DateTimeImmutable":private]=> object(DateTime)#9 (3) { ["date"]=> string(27) "-0001-11-30 16:27:57.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } }