Are there any best practices for checking the correctness of a date in PHP?

When checking the correctness of a date in PHP, it is important to validate the date format and ensure it is a valid date. One common approach is to use the `DateTime` class to create a new date object and then check if the date is valid using the `format` method. Additionally, you can use the `checkdate` function to verify if the date components (day, month, year) are valid.

$date = "2022-12-31";
$dateObj = DateTime::createFromFormat('Y-m-d', $date);
if ($dateObj && $dateObj->format('Y-m-d') === $date && checkdate($dateObj->format('m'), $dateObj->format('d'), $dateObj->format('Y'))) {
    echo "Date is valid";
} else {
    echo "Invalid date";
}