Hi,

It seems that the intellisense of PHP Tools does not detect methods from traits, is that correct? Possible to add support for it? Thank you.

    @phptools yes, traits are supported, including trait members aliasing. Also, within the trait, the editor resolves methods of all the classes that use the trait. Do you have a screenshot or a test case, when it's not working properly? Thank you.

    thanks wiechecprzemyslaw for the screenshot!

      7 months later

      Hello Jakub, I'm not sure if this is the best place to post this. This question seemed close enough that I didn't post a new question. If you think I should create a new question, please let me know.

      Before I get to the question, I'm using PHP Tools v1.27.12036 in VSCode and PHP 8.1.

      Now for the issue, so I am getting the following error regarding an aliased method (not sure if that's the correct language to describe this or not):

      It should also be noted that origGetHexId method does not appear in the Intellisense drop-down either (despite the other members of the class correctly appearing there):

      Here is the most relevant portion of the class:

      Finally, when I run the traits-and-precedence.php file, it runs with no errors, and the output is exactly as expected.

      It is always possible that I have done something incorrectly, but it appears to be an issue with PHP Tools to me.

      Please let me know if you need any additional information. Thank you!

      snoski thank you for the detailed description, and for the screenshots.

      We'll try it, it seems like a bug on our side.

        snoski a correct way of trait aliasing is to put the trait aliasing under the affected trait uses:

        class Song implements Identifiable
        {
            use IdentifiableTrait, IdentifiableTraitImposter {
              IdentifiableTraitImposter::getHexId insteadof IdentifiableTrait;
              IdentifiableTrait ::getHexId as origGetHexId;
            }

        In this way, aliasing is correctly associated with the trait in its "trait adaptation block".

        Anyways; if it works in PHP, we should be able to work the same. We'll try to fix it within the next update.

        Closing the thread;

        • to properly alias trait methods, group both traits into one adaptation group (use IdentifiableTrait, IdentifiableTraitImposter { ...)
        • traits are supported in general; if anyone having any issue, please open a new thread :)

        thank you!

          Thank you Jakub. I can confirm this did solve my issue. Much appreciated!

          snoski thank you for the confirmation! Please let us know if there is anything else we can help with, or if we can improve!

            2 years later

            Hi JakubMisek I amb experiencing a resolution problem.
            It seems that traits are not scanned by default on version v1.50.15906

            This is what happens before going to trait definition

            And this is what occurs after having open the trait file

              temple thank you for the details.

              It seems more like the file (does not matter trait or not) has not been indexed.

              May I ask what's the trait's file relative path?

                Write a Reply...