Repository navigation
Conversation
A parameter typed `self` inside a trait resolved to the trait alone, so
members of the class named by @phpstan-require-extends or -implements were
reported as unknown on it. PHP flattens the trait into each class using it,
so the parameter holds one of those classes, just like $this. It now gets
the same bounds $this does. Laravel model traits hit this in every model
event closure: static::saving(static function (self $model) { ... }).
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves parameters typed
selfinside a trait against the class the trait's@phpstan-require-extends/@phpstan-require-implementsnames. They resolved to the trait alone, so every member of the required class was reported as unknown on them, while$thisin the same trait already saw those members.PHP flattens a trait into each class that uses it, so a
selfparameter holds one of those classes, exactly like$this. The parameter now gets the same bounds$thisgets fromtrait_context::extend_this_with_trait_bounds.Laravel model traits hit this in every model event closure:
On a ~5,000-file Laravel codebase this removed all 21 remaining
unknown_memberreports in its model traits; a member neither the trait nor the required class has is still reported.The check only applies when the parameter resolves to exactly the current trait, so
?selforself|Foounions are left as they were.Checks
self_typed_parameter_inside_trait_sees_required_class(method parameter and closure parameter, plus a still-reported unknown member); it fails without the changecargo test: all passcargo clippy --all-targets -- -D warningsandcargo fmt --check: cleanphpantom_lsp analyze --project-root examples/laravel: exactly the 4 expected errorsphp examples/laravel/assertions.php: all 369 assertions passChecklist
CHANGELOG.mdREADME.md,docs/,examples/)config-schema.json)the changes and why they are needed.
the changelog, and other user-facing content, and removed or corrected
anything inaccurate, unclear, or unnecessary.