- Notifications
You must be signed in to change notification settings - Fork11.5k
[12.x] when a method returns$this
set the return type tostatic
#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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
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 commentedJun 21, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
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: After: You might want to target master? |
071a9d3
intolaravel:12.xUh oh!
There was an error while loading.Please reload this page.
@NickSdot in your example, the fix would be for |
@browner12 correct. Not a biggie. Just wanted to point out that this is breaking. Anyway, Taylor merged so never mind me. 😅 |
Thanks for confirming. Fingers crossed, this seems like a highly unlikely scenario, but thanks for pointing it out! |
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 bestatic
overself
.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.