Skip to content

Conversation

@troizet
Copy link
Collaborator

@troizet troizet commented Oct 2, 2025

Fixed an issue where a trait used in an anonymous class was defined as being used in a wrapper class.

Example:

<?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()
                    {

                    }
                };
            }
        };
    }
}

before:
gh_8527_before

after:
gh_8527_after

  • Fixed incorrect detection of the used trait in the navigator for the above case

before:
navigator_before

after:
navigator_after

  • Fixed tests NavigatorTest
  • Added new tests in NavigatorTest and ImplementAbstractMethodsHintErrorTest

^Add meaningful description above

Click to collapse/expand PR instructions

By opening a pull request you confirm that, unless explicitly stated otherwise, the changes -

  • are all your own work, and you have the right to contribute them.
  • are contributed solely under the terms and conditions of the Apache License 2.0 (see section 5 of the license for more information).

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:

  1. Was this PR correctly labeled, did the right tests run? When did they run?
  2. Is this PR squashed?
  3. Are author name / email address correct? Are co-authors correctly listed? Do the commit messages need updates?
  4. Does the PR title and description still fit after the Nth iteration? Is the description sufficient to appear in the release notes?

If this PR targets the delivery branch: don't merge. (full wiki article)

…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
@troizet troizet added the PHP [ci] enable extra PHP tests (php/php.editor) label Oct 2, 2025
@troizet troizet requested review from junichi11 and tmysik October 2, 2025 15:44
@troizet troizet changed the title Fixed an issue where a trait used in an anonymous class was defined as being used in a wrapper class PHP: Fixed an issue where a trait used in an anonymous class was defined as being used in a wrapper class Oct 2, 2025
Copy link
Member

@tmysik tmysik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM but please, wait for @junichi11, if possible. Thank you!

@apache apache locked and limited conversation to collaborators Jan 7, 2026
@apache apache unlocked this conversation Jan 7, 2026
Copy link
Contributor

@matthiasblaesing matthiasblaesing left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@matthiasblaesing matthiasblaesing merged commit 17690b1 into apache:master Jan 11, 2026
59 of 61 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

PHP [ci] enable extra PHP tests (php/php.editor)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants