How can PHP developers ensure that their age calculation script accounts for leap years?

When calculating someone's age in PHP, it's important to consider leap years since they have an extra day in February. To account for leap years, developers can use PHP's built-in DateTime class to accurately calculate age by checking if the birth date falls before or after February 29th in a leap year.

$birthdate = new DateTime('1992-02-29');
$currentDate = new DateTime();
$age = $currentDate->diff($birthdate)->y;
echo $age;