Re: List of attributes
| From: | Rowan Tommins | Date: | Sun, 27 Sep 2020 10:15:28 +0000 |
| Subject: | Re: List of attributes | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-111937@lists.php.net to get a copy of this message | ||
On 27 September 2020 09:22:48 BST, Nicolas Grekas <nicolas.grekas@gmail.com> wrote:
>The A. syntax is consistent with the 1. list.
>I feel like syntax B is not desired and could be confusing from a
>grammar
>pov.
>BUT in syntax 2., we allow an attribute to be unprefixed (bar), so that
>syntax B is consistent with 2.
I think it's fairly straightforward to see #[...] as meaning "list of attributes",
rather than as "change meaning of all identifiers recursively". So, this will look for a
constant "MAGIC", not a nested attribute:
#[Foo(true, 42), Bar(MAGIC)] class X ...
Nested attributes are a slightly confusing concept anyway, because "normal" attributes are
always attached to something, but nested attributes occur in place of a normal value. I can see
their usefulness, but having the extra #[...] to say "not a normal value, extra magic happening
here" seems sensible.
Presumably we could also allow grouping of nested attributes such that this:
#[Foo(#[Bar, Baz]) class X ...
Would just be equivalent to this:
#[Foo([ #[Bar], #[Baz] ]) class X ...
Regards,
--
Rowan Tommins
[IMSoP]