diff --git a/system/Validation/FormatRules.php b/system/Validation/FormatRules.php index 1683fd8367a7..bc4301c2a086 100644 --- a/system/Validation/FormatRules.php +++ b/system/Validation/FormatRules.php @@ -344,6 +344,15 @@ public function valid_date(?string $str = null, ?string $format = null): bool $date = DateTime::createFromFormat($format, $str); $errors = DateTime::getLastErrors(); - return $date !== false && $errors !== false && $errors['warning_count'] === 0 && $errors['error_count'] === 0; + if ($date === false) { + return false; + } + + // PHP 8.2 or later. + if ($errors === false) { + return true; + } + + return $errors['warning_count'] === 0 && $errors['error_count'] === 0; } }