From 3bafbe64642b41de9248179f17b2bee0f56c6499 Mon Sep 17 00:00:00 2001 From: kenjis Date: Wed, 12 Oct 2022 11:26:54 +0900 Subject: [PATCH] fix: valid_date does not work in PHP 8.2 See https://github.com/php/php-src/issues/9431#issuecomment-1230316507 --- system/Validation/FormatRules.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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; } }