Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

The method returns a new instance, so it is still immutable, technically.


Then the whole thing is redundant.

If clone $var = DateTimeImmutable->modify()

Then this really doesn't solve anything.


Let'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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: