$date1 = $date2 = new DateTime(); $date2->add(new DateInterval('P3Y'));
$date2 contain the same date -- three years from now. I'd like to create two separate datetimes, one which is parsed from a string and one with three years added to it. Currently I've hacked it up like this:
$date2 = new DateTime($date1->format(DateTime::ISO8601));
but that seems like a horrendous hack. Is there a "correct" way to deep copy a DateTime object?
If you want to copy rather than reference an existing DT object, use
$a = clone $b;