3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function createDateFromFormat($format, $time) { $result = \DateTimeImmutable::createFromFormat($format, $time); var_dump(\DateTime::getLastErrors()); return $result; } var_dump(createDateFromFormat('Y-m-d', '2005-15-0')); var_dump(\DateTimeImmutable::createFromFormat('Y-m-d|', '2000-15-0')); $errors = \DateTime::getLastErrors(); var_dump(\DateTime::getLastErrors()); if (!empty($errors['warning_count'])) { return false; }
based on qlXIU
Output for 5.6.0 - 5.6.6, 5.6.8 - 5.6.30, 7.0.0 - 7.3.0rc3
array(4) { ["warning_count"]=> int(1) ["warnings"]=> array(1) { [9]=> string(27) "The parsed date was invalid" } ["error_count"]=> int(0) ["errors"]=> array(0) { } } object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2006-02-28 15:27:06.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2001-02-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } array(4) { ["warning_count"]=> int(1) ["warnings"]=> array(1) { [9]=> string(27) "The parsed date was invalid" } ["error_count"]=> int(0) ["errors"]=> array(0) { } }
Output for hhvm-3.15.4
array(4) { ["warning_count"]=> int(1) ["warnings"]=> array(1) { [9]=> string(27) "The parsed date was invalid" } ["error_count"]=> int(0) ["errors"]=> array(0) { } } object(DateTimeImmutable)#1 (1) { ["data":"DateTimeImmutable":private]=> object(DateTime)#3 (3) { ["date"]=> string(26) "2006-02-28 15:27:06.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } object(DateTimeImmutable)#3 (1) { ["data":"DateTimeImmutable":private]=> object(DateTime)#5 (3) { ["date"]=> string(26) "2001-02-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } array(4) { ["warning_count"]=> int(1) ["warnings"]=> array(1) { [9]=> string(27) "The parsed date was invalid" } ["error_count"]=> int(0) ["errors"]=> array(0) { } }
Output for 5.6.7
array(4) { ["warning_count"]=> int(1) ["warnings"]=> array(1) { [9]=> string(27) "The parsed date was invalid" } ["error_count"]=> int(0) ["errors"]=> array(0) { } } object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2006-02-28 15:27:07.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2001-02-28 00:00:00.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } array(4) { ["warning_count"]=> int(1) ["warnings"]=> array(1) { [9]=> string(27) "The parsed date was invalid" } ["error_count"]=> int(0) ["errors"]=> array(0) { } }