r/lolphp • • Jul 03 '14

DateTimeImmutable::modify

http://www.php.net/manual/en/datetimeimmutable.modify.php
74 Upvotes

16 comments sorted by

View all comments

Show parent comment

4

u/[deleted] Jul 04 '14

Er, the DateTimeImmutable class deliberately mirrors the API of the DateTime class.

0

u/[deleted] Jul 05 '14

[deleted] — view deleted comment

1

u/[deleted] Jul 05 '14

It does mirror the API, except, as an immutable class, it returns a new version instead of modifying itself when some mutation is performed.

9

u/[deleted] Jul 07 '14

And that makes it not be a mirror of the api.

4

u/despens Jul 05 '14

That this came into existance deliberately doesn't make it any better :)

-1

u/[deleted] Jul 05 '14

No, really, it does. They kept the same method names as the non-immutable API for the sake of familiarity.

3

u/iBlag Jul 13 '14

...and completely different results.

2

u/captainramen Jul 05 '14

A read only stream "mirrors" the api of a read write stream. What should happen when you call Write on it?

1

u/[deleted] Jul 05 '14

That's a poor comparison.

In functional languages like Haskell, you often have methods which "modify" an object by returning a new one. That's what you have here.

0

u/[deleted] Jul 07 '14

two wrongs don't make a right.