News for hackers. Stuff that matters.
Re:PHP DateTimeImmutable::modify() by masklinn on Friday July 04, 2014 @11:11AM (#7989065)
> The reason why the method is called 'modify' in PHP is because the old DateTime (mutable edition™) method was also called 'modify' and the two should be more or less drop-in replacements.

The old datetime's method modifies the object in place[-1], if you replace the old with the new it's not going to work anymore.

> Besides - what would you call a method that modifies a timestamp?

Replace[0]? withFieldValue[1]? add with a delta object, possibly relative[2]?

[-1] it also returns the object it was called on since 5.3.0, the method was introduced in 5.2.0

[0] https://docs.python.org/2/library/datetime.html#datetime.dat...

[1] http://joda-time.sourceforge.net/apidocs/org/joda/time/DateT...

[2] http://msdn.microsoft.com/en-us/library/system.datetime.add(...

Re:PHP DateTimeImmutable::modify() by shawnz on Friday July 04, 2014 @11:18AM (#7989097)
> The old datetime's method modifies the object in place[-1], if you replace the old with the new it's not going to work anymore.

Of course it would be impossible to make the APIs exactly the same, because the two classes have different behaviour. But shouldn't they at least strive to make the APIs as similar as possible?

Re:PHP DateTimeImmutable::modify() by masklinn on Friday July 04, 2014 @12:34PM (#7989402)
> But shouldn't they at least strive to make the APIs as similar as possible?

No, not when the behavior is completely dissimilar and the method name is highly misleading.

Re:PHP DateTimeImmutable::modify() by shawnz on Friday July 04, 2014 @01:08PM (#7989512)
The behaviour is not completely dissimilar. The only difference between the two methods is what is done with the result. In fact, every method in that class parallels one from the other class in exactly that way, and that behaviour is described clearly on the documentation page for the class:

> This class behaves the same as DateTime except it never modifies itself but returns a new object instead.

http://www.php.net/manual/en/class.datetimeimmutable.php

Re:PHP DateTimeImmutable::modify() by Sharlin on Friday July 04, 2014 @11:25AM (#7989130)
> The old datetime's method modifies the object in place[-1], if you replace the old with the new it's not going to work anymore.

All the old datetime's methods modify the object in place, while none of DateTimeImmutable's methods do. It's not meant to be a drop-in replacement.

Re:PHP DateTimeImmutable::modify() by riffraff on Friday July 04, 2014 @11:59AM (#7989265)
but then why keep a confusing name and documentation instead of just using something like `withModification` ?