3v4l.org

run code in 300+ PHP versions simultaneously
<?php class DateTimeType { private const FORMAT = 'Y-m-d H:i:s'; private const TIMEZONE = 'Europe/Berlin'; public static function isValidDateTimeOld(string $value): bool { $date = DateTime::createFromFormat(self::FORMAT, $value, new DateTimeZone(self::TIMEZONE)); $errors = DateTime::getLastErrors(); return $date && $errors['warning_count'] === 0 && $errors['error_count'] === 0; } public static function isValidDateTimeNew(string $value): bool { $date = DateTime::createFromFormat(self::FORMAT, $value, new DateTimeZone(self::TIMEZONE)); $errors = DateTime::getLastErrors(); return $date && !$errors; } } $dateTimeToCheck = '2022-02-17 13:37:00'; var_dump(DateTimeType::isValidDateTimeOld($dateTimeToCheck)); var_dump(DateTimeType::isValidDateTimeNew($dateTimeToCheck));
Output for git.master, git.master_jit
Warning: Trying to access array offset on value of type bool in /in/hFvIJ on line 14 bool(false) bool(true)
Output for rfc.property-hooks
Warning: Trying to access array offset on false in /in/hFvIJ on line 14 bool(false) bool(true)

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
15.7 ms | 406 KiB | 5 Q