PHP: Fixed an issue where a trait used in an anonymous class was defined as being used in a wrapper class#8883
Merged
matthiasblaesing merged 1 commit intoapache:masterfrom Jan 11, 2026
Conversation
…s being used in a wrapper class.
Example:
```php
<?php
trait MyTrait
{
abstract function doSomething();
public function doNothing()
{
}
}
class MysClass
{
public function getObject()
{
return new class() {
public function getMyTraitAwareObject()
{
return new class() {
use MyTrait;
public function doSomething()
{
}
};
}
};
}
}
```
- Fixed the ImplementAbstractMethodsHintError hint for the above case [apacheGH-8527]
- Fixed incorrect detection of the used trait in the navigator for the above case
- Fixed tests NavigatorTest
- Added new tests in NavigatorTest and ImplementAbstractMethodsHintErrorTest
tmysik
approved these changes
Oct 2, 2025
Member
tmysik
left a comment
There was a problem hiding this comment.
LGTM but please, wait for @junichi11, if possible. Thank you!
matthiasblaesing
approved these changes
Jan 11, 2026
Contributor
There was a problem hiding this comment.
I looked through the changes and they look sane to me. The golden values for the new tests look sane. The updated golden files match what I would expect and also look good to me after the change.
Manual testing showed, that navigation works correctly.
My understanding is, that this works because the modification changes the UsedTraitsVisitor so that is does not recursively descent into the class structure, but only scans the toplevel block, which matches my understanding of the use statement.
This being reviewed now by two people and having been open for three months, I think it is time to merge.
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.
Fixed an issue where a trait used in an anonymous class was defined as being used in a wrapper class.
Example:
ImplementAbstractMethodsHintErrorhint for the above case [Anonymous class using a trait with asbtract method inside another class #8527]before:

after:

before:

after:

NavigatorTestNavigatorTestandImplementAbstractMethodsHintErrorTest^Add meaningful description above
Click to collapse/expand PR instructions
By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -
Please make sure (eg.
git log) that all commits have a valid name and email address for you in the Author field.If you're a first time contributor, see the Contributing guidelines for more information.
If you're a committer, please label the PR before pressing "Create pull request" so that the right test jobs can run.
PR approval and merge checklist:
If this PR targets the delivery branch: don't merge. (full wiki article)