What is the best way to handle adding a year to a timestamp in PHP, taking into account leap years?

When adding a year to a timestamp in PHP, it's important to consider leap years to ensure accuracy. One way to handle this is by using the DateTime class in PHP, which automatically takes care of leap years when adding intervals. By using the DateTime class, you can easily add a year to a timestamp while accounting for leap years.

// Create a DateTime object from a timestamp
$timestamp = time();
$date = new DateTime("@$timestamp");

// Add a year to the date
$date->add(new DateInterval('P1Y'));

// Get the updated timestamp
$new_timestamp = $date->getTimestamp();

echo date('Y-m-d H:i:s', $new_timestamp);