Skip to content

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

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

ext/date: Change return type to static#23317
arshidkv12 wants to merge 5 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
Comment thread ext/date/php_date.stub.php Outdated

@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

@derickr derickr 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.

Mostly LGTM.

Comment thread ext/date/php_date.stub.php Outdated
@kocsismate

Copy link
Copy Markdown
Member

You should re-run gen_stub.php now to make the build green

@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.

But I let Derick merge it when he looked at it. An UPGRADING note would probably be also useful, just like for the other recent return type changes.

Comment thread UPGRADING
- Date:
. Added a new Time\Duration class.
RFC: https://wiki.php.net/rfc/duration_class
. The following DateTime, DateTimeImmutable, DateTimeZone, DateInterval, and DatePeriod methods now have tentative static return types:

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 should go to the Changed Functions section

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.

3 participants