What potential pitfalls should be considered when using date ranges in PHP for determining age groups?

When using date ranges in PHP for determining age groups, one potential pitfall to consider is the handling of leap years. Leap years can affect the calculation of age, especially when using date differences to determine someone's age group. To address this issue, it's important to account for leap years when calculating age based on date ranges.

// Calculate age based on date ranges with leap year handling
$birthDate = new DateTime('1990-02-29');
$currentDate = new DateTime('2022-02-28');

$age = $birthDate->diff($currentDate)->y;

echo "Age: " . $age;