6 ms·
The method returns a new instance, so it is still immutable, technically.
by arankine 12y ago
The method returns a new instance, so it is still immutable, technically.
- nkozyra 12y agoThen 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.