Skip to content

ext/date: Change return type to static - #23317

Open
arshidkv12 wants to merge 2 commits into
php:masterfrom
arshidkv12:date-static
Open

ext/date: Change return type to static#23317
arshidkv12 wants to merge 2 commits into
php:masterfrom
arshidkv12:date-static

Conversation

@arshidkv12

@arshidkv12 arshidkv12 commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Use static return types for DateTime and related methods that preserve the called class.

ext/date: Fix DateTime return types for subclasses
@arshidkv12 arshidkv12 changed the title ext/date: Fix DateTime return types for subclasses ext/date: Change return type to static Aug 16, 2026
* @tentative-return-type
*/
public static function createFromDateString(string $datetime): DateInterval {}
public static function createFromDateString(string $datetime): static {}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is not completely right currently: always a DateInterval is returned, not the class which was invoked.

@kocsismate kocsismate left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the changes. There's a new date api in the works, but these classes will be with us for quite a lot of time, so I think it makes sense to improve them, especially because most of them are only tentative types.

There's a few declared types which are demoted to tentative types: at first, I was worried about them that they broke BC... But then I realized that static can substitute the original class, so I think it's a good solution.

LGTM, but I'm not approving the PR, let's wait for @derickr's review. And @TimWolla may also have opinion.

@kocsismate
kocsismate requested a review from TimWolla August 25, 2026 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants