Skip to content

Override static in return types with self in final classes - #17724

Closed
rekmixa wants to merge 23 commits into
php:masterfrom
rekmixa:feature/override_static_with_self_in_final_classes
Closed

Override static in return types with self in final classes#17724
rekmixa wants to merge 23 commits into
php:masterfrom
rekmixa:feature/override_static_with_self_in_final_classes

Conversation

@rekmixa

@rekmixa rekmixa commented Feb 6, 2025

Copy link
Copy Markdown
Contributor

This PR adds the ability to replace static with self in the return types in the final classes, provided that the prototype of the final class has a static return method.

Example of how it should work:

interface A {
    public function someMethod(): static;
}
final class B implements A {
    public function someMethod(): self { /** */ }
}
  • There are no changes that break backward compatibility or covariance logic.

More information in the issue: #17725

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

@rekmixa please define what exactly you propose. (e.g. some code didn't work as expected and started to work after the patch).

I'm not sure if this patch is a fix or a new feature that requries RFC and discussion, how it's going to coexists with type variance, etc

@iluuu1994 @nielsdos @arnaud-lb please take care about this PR.

Comment thread Zend/zend_inheritance.c Outdated
…tests to folder Zend/tests/type_declarations/variance/override_static_with_self

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

Conceptually, this seems correct to me. Please see my preliminary review comments.

Comment thread Zend/zend_inheritance.c Outdated
Comment thread Zend/zend_inheritance.c Outdated
Comment thread Zend/zend_inheritance.c Outdated
Comment thread Zend/zend_inheritance.c Outdated
@rekmixa

rekmixa commented Feb 13, 2025

Copy link
Copy Markdown
Contributor Author

@nielsdos do i need to squash all commits in this PR?

@rekmixa
rekmixa requested a review from ndossche February 13, 2025 07:34
@ndossche

Copy link
Copy Markdown
Member

do i need to squash all commits in this PR?

No, we will squash on merge. Squashing makes it harder for us to review what has changed since our reviews.

@ndossche ndossche 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 think this is right now, thanks. But I haven't worked with this code a lot, so this needs more eyes, especially since this is deep engine code.
cc @iluuu1994 @arnaud-lb

This may also need discussion on the ML so we know for sure there are no objections.

@ndossche
ndossche dismissed their stale review February 14, 2025 22:04

Requested changes were performed

@rekmixa

rekmixa commented Feb 15, 2025

Copy link
Copy Markdown
Contributor Author

This may also need discussion on the ML so we know for sure there are no objections.

By the way, i already created discussion in the ML: https://externals.io/message/126367

@ndossche

Copy link
Copy Markdown
Member

This may also need discussion on the ML so we know for sure there are no objections.

By the way, i already created discussion in the ML: https://externals.io/message/126367

Ah good to know, I missed this.

Comment thread Zend/zend_inheritance.c Outdated
Comment thread Zend/zend_inheritance.c Outdated
Comment thread Zend/zend_inheritance.c Outdated
Comment thread Zend/zend_inheritance.c Outdated

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

LGTM now. Thank you @rekmixa! Given there were no objections on the list, it should be ok to merge this in a week or so.

Comment thread Zend/zend_inheritance.c Outdated
@rekmixa

rekmixa commented Feb 19, 2025

Copy link
Copy Markdown
Contributor Author

LGTM now. Thank you @rekmixa! Given there were no objections on the list, it should be ok to merge this in a week or so.

Thanks for your comments. Can you tell me if this PR will be merged in 8.4 or 8.5?

@iluuu1994

Copy link
Copy Markdown
Member

8.5. Stable branches only receive bug fixes.

@iluuu1994 iluuu1994 closed this in 4f5136c Mar 5, 2025
@iluuu1994

Copy link
Copy Markdown
Member

Thanks @rekmixa!

adrian-enspired pushed a commit to adrian-enspired/php-src that referenced this pull request Aug 4, 2026
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.

4 participants