Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[12.x] when a method returns $this set the return type to static #56092

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

Open
wants to merge 1 commit into
base: 12.x
Choose a base branch
from

Conversation

browner12
Copy link
Contributor

while PHP is a little lenient here, the more accurate return type when returning $this is static, not self.

when returning new static() the return type should also be static over self.

this may be a little pedantic, but it should be slightly more accurate. also this is forward looking in case PHP ever decided to get more strict in their type checks regarding these return types.

while PHP is a little lenient here, the more accurate return type when returning `$this` is static, not self.

when returning `new static()` the return type should also be `static` over `self`.
@NickSdot
Copy link
Contributor

NickSdot commented Jun 21, 2025

If the return type of an overridden method in a child class is the explicit child class, this will cause an incompatible declaration error.

Before:
https://3v4l.org/iQc6R

After:
https://3v4l.org/fmclK

You might want to target master?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants