-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Added missing obj methods to DateTimeInterface #13491
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -316,12 +316,43 @@ interface DateTimeInterface | |
/** @tentative-return-type */ | ||
public function format(string $format): string; | ||
|
||
/** @tentative-return-type */ | ||
public function modify(string $modifier): DateTimeInterface|false; | ||
|
||
|
||
/** @tentative-return-type */ | ||
public function add(DateInterval $interval): DateTimeInterface; | ||
|
||
/** @tentative-return-type */ | ||
public function sub(DateInterval $interval): DateTimeInterface; | ||
|
||
/** @tentative-return-type */ | ||
public function getTimezone(): DateTimeZone|false; | ||
|
||
/** @tentative-return-type */ | ||
public function setTimezone(DateTimeZone $timezone): DateTimeInterface; | ||
|
||
/** @tentative-return-type */ | ||
public function getOffset(): int; | ||
|
||
/** @tentative-return-type */ | ||
public function getMicroseconds(): int; // TODO: Rename https://github.com/php/php-src/pull/13486 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This one method is definitely missing from the interface right now, so maybe this one could be committed separately without any further discussion. |
||
|
||
/** @tentative-return-type */ | ||
public function setMicroseconds(int $microseconds): static; // TODO: Rename https://github.com/php/php-src/pull/13486 | ||
|
||
/** @tentative-return-type */ | ||
public function setTime(int $hour, int $minute, int $second = 0, int $microsecond = 0): DateTimeInterface; | ||
|
||
/** @tentative-return-type */ | ||
public function setDate(int $year, int $month, int $day): DateTimeInterface; | ||
|
||
/** @tentative-return-type */ | ||
public function setISODate(int $year, int $week, int $dayOfWeek = 1): DateTimeInterface; | ||
|
||
/** @tentative-return-type */ | ||
public function setTimestamp(int $timestamp): DateTimeInterface; | ||
|
||
/** @tentative-return-type */ | ||
public function getTimestamp(): int; | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO adding any mutator methods to the interface is not applicable now, because the two implementations have different behavior regarding mutability. In practice, this means that users of the
DateTimeInterface
should deal with the possibility that the interface implementation is either mutable or immutable.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the behavior is different, but this kind of difference is not possible to be defined in method signatures.
Actually your example should be
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree mutator methods should not be added. When one works with an interface instance it's impossible to know whether it's a mutable or immutable instance. If PHPStan, IDE etc. need some more information then we can write stub files for them. I would leave it as is (hoping this interface will be removed together with mutable class).