On 13 May 2023 16:40:27 BST, Robert Landers <landers.rob...@gmail.com> wrote: > Most of the time, you want the unqualified name > ... >This is especially important when using traits and aliases:
I don't think trait renaming is the same thing as aliasing a qualified name. In a sense, it's actually the opposite: with a trait, the compiler is inserting the code of the method under the new name, and the name from the trait can no longer be used to access it; for namespace imports, the compiler is substituting the fully-qualified name, and the *local alias* can no longer be used to access it. The "real" name of a method copied in from a trait is whatever it's called in the target class, but the "real" name of a function aliased with "use function ... as ..." is undoubtedly its fully-qualified name. >In this case, if you want to use nameof(TEST) in an error message or >something else, it would be surprising to get \A\A instead of TEST. Would it? As I said before, my intuition was completely the opposite, that one of the advantages of writing nameof(TEST) rather than just 'TEST' is that it would resolve namespace imports the same way ::class does. Can you give an example of such an error message that would want to expose the local alias? >So, for your example, we can instead call nameof(\Acme\bar(...)) >instead of the aliased name when passing to another context: > >use function Acme\bar as foo; >... >#[SomeAttribute(callback: nameof(\Acme\bar(...))] >... > >I hope this helps! Not really, I'm afraid. If I have to write out the fully-qualified name, why would I bother with nameof() rather than just using a string? The more I read in this thread, the less I understand what the point of nameof() actually is, and how it would be used. Regards, -- Rowan Tommins [IMSoP] -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php