3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function createDateFromFormat($format, $time) { $result = \DateTimeImmutable::createFromFormat($format, $time); if (!$result || \DateTimeImmutable::getLastErrors()['warning_count']) { return false; } return $result; } var_dump(\DateTime::createFromFormat('Y-m-d', '2005-12-1')); var_dump(\DateTime::createFromFormat('Y-m-d', '2005')); // should be false var_dump(\DateTime::createFromFormat('Y-m-d', '0-0-0')); // should be false 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(get_class(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 qq72F
Output for 5.6.0 - 5.6.30, 7.0.0 - 7.1.7, 7.1.20 - 7.3.0rc3
object(DateTime)#1 (3) { ["date"]=> string(26) "2005-12-01 16:57:04.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) object(DateTime)#1 (3) { ["date"]=> string(27) "-0001-11-30 16:57:04.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2005-12-01 16:57:04.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) object(DateTimeImmutable)#1 (3) { ["date"]=> string(27) "-0001-11-30 16:57:04.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } string(17) "DateTimeImmutable" bool(false) bool(false)
Output for 7.1.10

Process exited with code 137.
Output for hhvm-3.15.4
object(DateTime)#1 (3) { ["date"]=> string(26) "2005-12-01 16:57:04.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) object(DateTime)#1 (3) { ["date"]=> string(27) "-0001-11-30 16:57:04.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#1 (1) { ["data":"DateTimeImmutable":private]=> object(DateTime)#3 (3) { ["date"]=> string(26) "2005-12-01 16:57:04.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:57:04.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } string(17) "DateTimeImmutable" bool(false) bool(false)