Skip to content

Commit 4887c2a

Browse files
authored
Merge pull request #6671 from kenjis/fix-valid_date-php82
refactor: valid_date does not work in PHP 8.2
2 parents 8255215 + 3bafbe6 commit 4887c2a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

system/Validation/FormatRules.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,15 @@ public function valid_date(?string $str = null, ?string $format = null): bool
344344
$date = DateTime::createFromFormat($format, $str);
345345
$errors = DateTime::getLastErrors();
346346

347-
return $date !== false && $errors !== false && $errors['warning_count'] === 0 && $errors['error_count'] === 0;
347+
if ($date === false) {
348+
return false;
349+
}
350+
351+
// PHP 8.2 or later.
352+
if ($errors === false) {
353+
return true;
354+
}
355+
356+
return $errors['warning_count'] === 0 && $errors['error_count'] === 0;
348357
}
349358
}

0 commit comments

Comments
 (0)