Op ma 15 mei 2023 om 20:06 schreef Rowan Tommins <rowan.coll...@gmail.com>:
>
> On 15 May 2023 14:07:31 BST, Lydia de Jongh <flexj...@gmail.com> wrote:
> >> ...
> >> #[SomeAttribute(callback: nameof(\Acme\bar(...))]
> >> ...
> >
> >This callback to nameof()..... is really terrible  😣😣
>
> Just to be clear, the "callback:" in that example is existing syntax for
named parameters, not part of the nameof() syntax. A positional parameter
would just look like this:
>
> #[SomeAttribute(nameof(\Acme\bar(...))]
>
> That's the same number of characters as this:
>
> #[SomeAttribute(\Acme\bar(...)::nameof]
>

oops 🤭😳 tx!
So because nameof() is not a real function, it works as parameter in
attributes.... nice!


> The main difference is the the function-ish syntax makes it a bit clearer
what you're asking for the name of, because the whole thing is in
parentheses. There might even be cases where the function-ish syntax needs
additional parentheses anyway, like are needed in (new
Something)->doSomething()

Sure.
I just think we need both nameof() and ::nameof
Just like we have get_class() and ::class.....

>
> Changing "nameof" to "function", "method", etc depending on type doesn't
really add anything, since the output is always a string anyway, not some
type-specific thing.

True.... I only suggested that  because '::class' exists and not something
like: ::nameof or ::pathof.
And thought that maybe the choice for ::class was deliberately

Op ma 15 mei 2023 om 19:45 schreef Robert Landers <landers.rob...@gmail.com
>:
>
> There are no magic constants in this RFC.

May I ask why you do not add a magic constant as part of your RFC?
If I would make an RFC for it, it would be almost a duplicate of yours.....
And I cannot contribute to the codebase, as I do not know C or in whatever
language php is written :-(
But I could help with documenting and writing for the RFC.


Quote from RFC:
"When getting the name of constants and functions, the name will NOT be the
full name, but the lexical name. This means that if the name is
use'd, it will be that name. However, if the full name is used in
the nameof(), the full name is returned. It's probably easiest to show
this with an example:
<...>

    echo nameof(MY_CONST); // MY_CONST
    echo nameof(\Name\MY_CONST); // \Name\MY_CONST
"

This looks confusing to me. As it is best practice to import with use and
without using fully qualified names inside your code.
 Maybe consider a second bool parameter to full name or not.
Or have a second 'function' like: fullnameof()

Looking again at your RFC.... I just realized.... it is about variables,
properties, functions, methods etc. not about classes... 🤔 (ploink)
In that case you are right that you mostly want the unqualified name. Most
of them do not even have a different fully qualified name.
Only items that are namespace aware have that.
But local variables and items inside a class, they have just one name. Or
am I mistaken here?
So maybe it does not help to talk about fully qualified or not.



Greetz, Lydia

Reply via email to