Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[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

Merged
taylorotwell merged 1 commit intolaravel:12.xfrombrowner12:AB-self-vs-static
Jun 22, 2025

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

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 commentedJun 21, 2025
edited
Loading

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?

rodrigopedra reacted with thumbs up emoji

@taylorotwelltaylorotwell merged commit071a9d3 intolaravel:12.xJun 22, 2025
62 checks passed
@browner12
Copy link
ContributorAuthor

@NickSdot in your example, the fix would be forSomeChild->foo() to also returnstatic as well, correct?

@browner12browner12 deleted the AB-self-vs-static branchJune 23, 2025 14:52
@NickSdot
Copy link
Contributor

@browner12 correct. Not a biggie. Just wanted to point out that this is breaking. Anyway, Taylor merged so never mind me. 😅

@browner12
Copy link
ContributorAuthor

Thanks for confirming.

Fingers crossed, this seems like a highly unlikely scenario, but thanks for pointing it out!

NickSdot reacted with thumbs up emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@browner12@NickSdot@taylorotwell

[8]ページ先頭

©2009-2025 Movatter.jp