3 ms·
Then the whole thing is redundant. If clone $var = DateTimeImmutable->modify() Then this really doesn't solve anything.
by nkozyra 12y ago
Then the whole thing is redundant.
If clone $var = DateTimeImmutable->modify()
Then this really doesn't solve anything.
- pilif 12y agoLet's compare the old thing: $date = new DateTime(); $other_date = $date->modify('+ 1 day'); // $date is now tomorrow with the new thing: $date = new DateTimeImmutable(); $other_date = $date->modify('+ 1 day'); // $date is still today Then, yes, clone($date_time)->modify() is equivalent to calling modify() on a $date_time, but the problem starts when you pass DateTime instances into functions because you just can't know what the function is going to do to that date object. This means that you have to be very defensive, constantly calling clone() or you'll have your dates altered behind your back from some library that's called by a library you're calling.