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(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 TXKos
Output for 5.6.0 - 5.6.29, 5.6.38, 7.0.0 - 7.3.1
object(DateTime)#1 (3) { ["date"]=> string(26) "2005-12-01 16:50:31.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) object(DateTime)#1 (3) { ["date"]=> string(27) "-0001-11-30 16:50:31.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2005-12-01 16:50:31.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) object(DateTimeImmutable)#1 (3) { ["date"]=> string(27) "-0001-11-30 16:50:31.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2005-12-01 16:50:31.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) bool(false)
Output for hhvm-3.15.4
object(DateTime)#1 (3) { ["date"]=> string(26) "2005-12-01 16:50:31.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) object(DateTime)#1 (3) { ["date"]=> string(27) "-0001-11-30 16:50:31.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:50:31.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:50:31.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } object(DateTimeImmutable)#5 (1) { ["data":"DateTimeImmutable":private]=> object(DateTime)#7 (3) { ["date"]=> string(26) "2005-12-01 16:50:31.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } } bool(false) bool(false)
Output for 5.6.30
object(DateTime)#1 (3) { ["date"]=> string(26) "2005-12-01 16:50:32.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) object(DateTime)#1 (3) { ["date"]=> string(27) "-0001-11-30 16:50:32.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2005-12-01 16:50:32.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) object(DateTimeImmutable)#1 (3) { ["date"]=> string(27) "-0001-11-30 16:50:32.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } object(DateTimeImmutable)#1 (3) { ["date"]=> string(26) "2005-12-01 16:50:32.000000" ["timezone_type"]=> int(3) ["timezone"]=> string(16) "Europe/Amsterdam" } bool(false) bool(false)