Re: [RFC] Shorter attribute syntax
| From: | Theodore Brown | Date: | Thu, 04 Jun 2020 12:39:51 +0000 |
| Subject: | Re: [RFC] Shorter attribute syntax | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-110369@lists.php.net to get a copy of this message | ||
On Thu, June 4, 2020 at 5:37 AM Ilija Tovilo <tovilo.ilija@gmail.com> wrote:
>>> Does the PHP parser prevent us from adopting #[attr]? I presume
>>> C#'s [attr] syntax and C++'s [[attr]] are impossible due to
>>> PHP's short array syntax.
>>
>> yes, that would create ambiguity in the parser since
#
>> (just
>> like //) is for comments.
>
> I've mentioned this off-list before. If we consider @@ with a BC
> break we could also consider #[] by making #[ a symbol.
> This is also a breaking change but a probably similarly small one.
> It would break code like this:
>
> # Comments still work
> #[ <-- But they can't start with #[
>
> To me both of those look acceptable but #[ looks nicer (but that's
> just my personal preference).
Hi Ilija,
From the perspective of looks I don't have a strong preference
between them. There are two main reasons the RFC doesn't propose the
#[] syntax. First of all, I would consider this a larger BC break
than @@. Although hash style comments are relatively uncommon, some
codebases do use them, and I don't think we can presume to say that
it "isn't useful" to begin a comment with a [ (as can be said about
using multiple suppression operators).
Secondly, the #[] syntax is 50% more verbose than the two character
@@ proposal; Rust is the only language I found that uses three
characters for its attribute syntax like this.
```
Best regards,
Theodore