# [RFC] Shorter Attribute Syntax Change RFC 0.2

- Thread: https://externals.io/message/111312
- Original archive: https://news-web.php.net/php.internals/111312
- Started by Derick Rethans on 2020-08-04T13:45:30+00:00
- Messages: 86
- RFC: Shorter Attribute Syntax Change (Implemented (PHP 8.0)) — https://externals.io/rfc/shorter_attribute_syntax_change.md
- Page 1 of 4: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/111312.md?page=2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #111312 — Derick Rethans — 2020-08-04T13:45:30+00:00

URL: https://externals.io/message/111312#111312

Hi,

Out of Banjamin's suggestion[1], I've updated the Shorter Attribute 
Syntax Change RFC to reflect that process:

https://wiki.php.net/rfc/shorter_attribute_syntax_change

Patches and comments welcome.

FWIW, this has an excemption from the RM Sara as per [2]:

> * Shorter Attribute Syntax Change
>    - Joe/Derick - Please make sure this RFC moves along and reaches
>      conclusion by beta3, as discussed previously.


cheers,
Derick

[1] https://externals.io/message/111218#111261
[2] https://externals.io/message/111286#111286

-- 
PHP 7.4 Release Manager
Host of PHP Internals News: https://phpinternals.news
Like Xdebug? Consider supporting me: https://xdebug.org/support
https://derickrethans.nl | https://xdebug.org | https://dram.io
twitter: @derickr and @xdebug

---

## #111314 — Benas IML — 2020-08-04T13:58:28+00:00

URL: https://externals.io/message/111312#111314 · In reply to: #111312

A little nitpick but I don't think that `@@` really signals familiarity
with docblocks.

Nevertheless, I really like `@[...]`. I think it combines best of the both
worlds (little-to-no BC breaks, ending delimiter, etc.) and also looks
aesthetically pleasing.

Best regards,
Benas



> Hi,
>
> Out of Banjamin's suggestion[1], I've updated the Shorter Attribute
> Syntax Change RFC to reflect that process:
>
> https://wiki.php.net/rfc/shorter_attribute_syntax_change
>
> Patches and comments welcome.
>
> FWIW, this has an excemption from the RM Sara as per [2]:
>
> > […]
>
>
> cheers,
> Derick
>
> [1] https://externals.io/message/111218#111261
> [2] https://externals.io/message/111286#111286
>
> --
> PHP 7.4 Release Manager
> Host of PHP Internals News: https://phpinternals.news
> Like Xdebug? Consider supporting me: https://xdebug.org/support
> https://derickrethans.nl | https://xdebug.org | https://dram.io
> twitter: @derickr and @xdebug
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

## #111315 — Benjamin Eberlei — 2020-08-04T14:02:55+00:00

URL: https://externals.io/message/111312#111315 · In reply to: #111312

> Hi,
>
> Out of Banjamin's suggestion[1], I've updated the Shorter Attribute
> Syntax Change RFC to reflect that process:
>
> https://wiki.php.net/rfc/shorter_attribute_syntax_change
>
> Patches and comments welcome.
>
> FWIW, this has an excemption from the RM Sara as per [2]:
>
> > […]
>

In combination to the existing proposals we already voted one, this RFC
includes a fourth option that has not been discussed before,
and could be the compromise we are all looking for :-)

@[Attr] combines both the with to use the familiar @ of many, and the wish
to have a closing symbol/termination symbol that many others have.

It does not have the downsides that Tyson found w.r.t. to #[Attr] being
interpreted as comment on PHP 7, but that also means its not forward
compatible like #[Attr] is.

It provides a small BC break where code written as @[$foo, $bar] = baz();
or $foo = @["bar" => $baz]; will not compile on PHP 8 anymore, but that can
be easily
fixed by writing it with a space between @ and [.


>
> cheers,
> Derick
>
> [1] https://externals.io/message/111218#111261
> [2] https://externals.io/message/111286#111286
>
> --
> PHP 7.4 Release Manager
> Host of PHP Internals News: https://phpinternals.news
> Like Xdebug? Consider supporting me: https://xdebug.org/support
> https://derickrethans.nl | https://xdebug.org | https://dram.io
> twitter: @derickr and @xdebug
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

## #111316 — Dennis Birkholz — 2020-08-04T14:14:12+00:00

URL: https://externals.io/message/111312#111316 · In reply to: #111312

Hi,

Am 04.08.20 um 15:45 schrieb Derick Rethans:
> Patches and comments welcome.

if the syntax will be changed to having a closing delimiter, I would
really like to have symmetrical delimiters, like @{ }@ or something like
that. ] as a closing delimiter just seems to collide with the array
syntax and does not provide much parsing benefit to me.

Greets
Dennis

---

## #111317 — Sebastian Bergmann — 2020-08-04T14:19:03+00:00

URL: https://externals.io/message/111312#111317 · In reply to: #111312

Am 04.08.2020 um 15:45 schrieb Derick Rethans:
> https://wiki.php.net/rfc/shorter_attribute_syntax_change

This is probably a wiki/markup issue: the RFC shows "«Attr»" instead of 
"<<Attr>>" for the original syntax.

---

## #111318 — David Rodrigues — 2020-08-04T14:19:10+00:00

URL: https://externals.io/message/111312#111318 · In reply to: #111315

Suggestions:

$(Attribute()) (available)
$[Attribute()] (available)
<<Attribute(1 \>> 2)>> (like strings escapes)

About $() syntax:

   - Number of required characters: (2+1)
   - Has end delimiter: yes
   - Allow grouping: yes
   - Forward compatibility in PHP 7: yes
   - Breaks BC of valid PHP 7 codes: no
   - Used by other languages: no?
   - Familiar with Docblock Usage: I don't know
   - Difficulties with Userland Parsers: I don't know

And my another suggestion is use a more verbose for now, until we have a
good consensus about it "using attribute()":

- Number of required characters: (16+1)
- Has end delimiter: yes
- Allow grouping: yes
- Forward compatibility in PHP 7: yes
- Breaks BC of valid PHP 7 codes: no
- Used by other languages: no?
- Familiar with Docblock Usage: I don't know
- Difficulties with Userland Parsers: I don't know


Atenciosamente,
David Rodrigues


Em ter., 4 de ago. de 2020 às 11:03, Benjamin Eberlei <kontakt@beberlei.de>
escreveu:

> 
>
> > […]
>
> In combination to the existing proposals we already voted one, this RFC
> includes a fourth option that has not been discussed before,
> and could be the compromise we are all looking for :-)
>
> @[Attr] combines both the with to use the familiar @ of many, and the wish
> to have a closing symbol/termination symbol that many others have.
>
> It does not have the downsides that Tyson found w.r.t. to #[Attr] being
> interpreted as comment on PHP 7, but that also means its not forward
> compatible like #[Attr] is.
>
> It provides a small BC break where code written as @[$foo, $bar] = baz();
> or $foo = @["bar" => $baz]; will not compile on PHP 8 anymore, but that can
> be easily
> fixed by writing it with a space between @ and [.
>
>
> > […]

---

## #111319 — Lynn — 2020-08-04T14:24:23+00:00

URL: https://externals.io/message/111312#111319 · In reply to: #111318

On Tue, Aug 4, 2020 at 4:19 PM David Rodrigues <david.proweb@gmail.com>
wrote:

> Suggestions:
>
> $(Attribute()) (available)
> $[Attribute()] (available)
> <<Attribute(1 \>> 2)>> (like strings escapes)
>

The syntax for the first two seems oddly pleasing when used within PHP.

---

## #111320 — Benjamin Eberlei — 2020-08-04T14:28:48+00:00

URL: https://externals.io/message/111312#111320 · In reply to: #111318

On Tue, Aug 4, 2020 at 4:19 PM David Rodrigues <david.proweb@gmail.com>
wrote:

> Suggestions:
>
> $(Attribute()) (available)
> $[Attribute()] (available)
> <<Attribute(1 \>> 2)>> (like strings escapes)
>

I had someone else suggest $[] to me today as well, funny coincidence :-)

Can you take the "@@ to @[] pull" request as a starting point to try if
this works with a patch?

https://github.com/php/php-src/pull/5928

This syntax is "not" familiar with docblock usage of @, as it doesn't
contain a @ :-D
It does pose difficulty for static analyers and userland parsers, because
they see the $ as a `T_VARIABLE` 
in PHP 7.


> About $() syntax:
>
>    - Number of required characters: (2+1)
>    - Has end delimiter: yes
>    - Allow grouping: yes
>    - Forward compatibility in PHP 7: yes
>    - Breaks BC of valid PHP 7 codes: no
>    - Used by other languages: no?
>    - Familiar with Docblock Usage: I don't know
>    - Difficulties with Userland Parsers: I don't know
>
> And my another suggestion is use a more verbose for now, until we have a
> good consensus about it "using attribute()":
>
>
>    - Number of required characters: (16+1)
>
>
>    - Has end delimiter: yes
>
>
>    - Allow grouping: yes
>
>
>    - Forward compatibility in PHP 7: yes
>
>
>    - Breaks BC of valid PHP 7 codes: no
>
>
>    - Used by other languages: no?
>
>
>    - Familiar with Docblock Usage: I don't know
>
>
>    - Difficulties with Userland Parsers: I don't know
>
>
This would definitely need a fully working patch to be a contender in the
vote.

- It's not forward compatibltle with PHP 7, because use of the syntax
would  lead to a fatal error on PHP 7 parsers or am I seeing something
wrong?
- its not a familiar syntax for PHP developers used to @ in docblocks

>
> Atenciosamente,
> David Rodrigues
>
>
> Em ter., 4 de ago. de 2020 às 11:03, Benjamin Eberlei <kontakt@beberlei.de>
> escreveu:
>
> > […]

---

## #111321 — Sara Golemon — 2020-08-04T15:01:40+00:00

URL: https://externals.io/message/111312#111321 · In reply to: #111315

> It provides a small BC break where code written as @[$foo, $bar] = baz();
> or $foo = @["bar" => $baz]; will not compile on PHP 8 anymore, but that can
> be easily
> fixed by writing it with a space between @ and [.
>
> If those are the potential breaks we're choosing between, I would favor
#[...] as it provides strong forward-compatibility to drive adoption and
use at the cost of a parse error that's easily fixed (even programmatically
with a very simple script).   @[...] provides no forward compat with a
roughly equal chance of easily fixed syntax break.

Given that, the choice seems obvious to me.
Change my mind?

-Sara

---

## #111322 — Jordi Boggiano — 2020-08-04T15:16:37+00:00

URL: https://externals.io/message/111312#111322 · In reply to: #111317

> Am 04.08.2020 um 15:45 schrieb Derick Rethans:
> > […]
>
> This is probably a wiki/markup issue: the RFC shows "«Attr»" instead 
> of "<<Attr>>" for the original syntax.
>
Given that every single thread about attributes contains an email like 
the above, no matter what we end up with I will be glad if it's not 
<<Attr>>.

Best,
Jordi

-- 
Jordi Boggiano
@seldaek - https://seld.be

---

## #111323 — Derick Rethans — 2020-08-04T15:28:23+00:00

URL: https://externals.io/message/111312#111323 · In reply to: #111321

> 
> 
> > […]
> If those are the potential breaks we're choosing between, I would 
> favor #[...] as it provides strong forward-compatibility to drive 
> adoption and use at the cost of a parse error that's easily fixed 
> (even programmatically with a very simple script).  @[...] provides no 
> forward compat with a roughly equal chance of easily fixed syntax 
> break.
> 
> Given that, the choice seems obvious to me. Change my mind?

I pretty much agree, but @[ … ] is there as a compromise as it does show 
some fmailiarity with the already existing @ in doc blocks.

cheers,
Derick

-- 
PHP 7.4 Release Manager
Host of PHP Internals News: https://phpinternals.news
Like Xdebug? Consider supporting me: https://xdebug.org/support
https://derickrethans.nl | https://xdebug.org | https://dram.io
twitter: @derickr and @xdebug

---

## #111324 — Theodore Brown — 2020-08-04T16:36:49+00:00

URL: https://externals.io/message/111312#111324 · In reply to: #111312

> Out of Banjamin's suggestion[1], I've updated the Shorter Attribute
> Syntax Change RFC to reflect that process:
> 
> https://wiki.php.net/rfc/shorter_attribute_syntax_change
> 
> Patches and comments welcome.

Hi Derick,

I don't agree with the main argument put forward in this RFC:

> The main concern is that @@ has no ending symbol and it's
> inconsistent with the language that it would be the only
> declaration or statement in the whole language that has no ending
> termination symbol.

Attributes are not a standalone statement or declaration; they are
metadata *on* a declaration. They cannot stand alone, but always
modify the following declaration, just as public and static modify
a method, or a type declaration modifies a parameter or property.

Modifying declarations (e.g. for visibility and type) do not have an
ending symbol. For example, we don't write something like:

    [public] function foo([int] $bar) {}

With the @@ syntax attributes a treated consistently with type and
visibility declarations:

    @@Jit
    public function foo(@@Deprecated int $bar) {}

So there is nothing inconsistent about not having a termination
symbol - this is in harmony with visibility and type declarations in
PHP, as well as the attribute syntax used by a majority of C family
languages. [1]

When it comes to supporting attribute grouping, I actually consider
this a downside of the #[], @[], and <<>> syntaxes. It complicates
the internal implementation, and makes it so developers have to
choose between two different syntaxes when adding more than one
attribute. In real-world use cases the @@ syntax is just as or even
more concise without the extra parser/compiler complexity:

    #[Attr1, Attr2] # 15 chars

    @@Attr1 @@Attr2 # 15 chars

    # 4 lines, 53 chars not counting whitespace
    @[
        AttrWithParam("foobar"),
        SomeOtherAttr("fizzbuzz"),
    ]

    # 2 lines, 52 chars
    @@AttrWithParam("foobar")
    @@SomeOtherAttr("fizzbuzz")

I agree that we want the best syntax, not necessarily the best
**looking** syntax. I still believe that the @@ syntax offers the best
balance here. It's familiar, concise without additional complexity,
and doesn't break useful syntax the way @[] and #[] do.

Kind regards,  
Theodore

[1]: https://wiki.php.net/rfc/shorter_attribute_syntax#comparison_to_other_languages

---

## #111332 — mail@pmmaga.net — 2020-08-04T22:07:12+00:00

URL: https://externals.io/message/111312#111332 · In reply to: #111312

Hi Derick,

I'd like to reinforce the idea that this RFC (as all RFCs) needs a Yes/No
primary vote which should attain a 2/3 majority to pass. As it was the case
with https://wiki.php.net/rfc/shorter_attribute_syntax, it had a primary
vote asking "Are you okay with re-voting on the attribute syntax for PHP
8.0?" and that vote passed with 50 to 8.
The primary vote on this RFC could be the exact same question, but I
believe the primary vote needs to be there. Without this primary vote, we
could be enacting a change that only (with 4 options) 25%+1 voters support,
which is clearly insufficient. However, if 2/3 of the voters agree that
something needs to change, they are also accepting that the change may not
be the one they prefer.

From the voting RFC (https://wiki.php.net/RFC/voting#required_majority):
"The primary vote of an RFC, determining overall acceptance of the
proposal, may only have two voting options and requires a 2/3 majority.
This means that the number of Yes votes must be greater than or equal to
the number of No votes multiplied by two."
On the same RFC we can also find information about the format of secondary
votes which mandates a simple majority, this should disqualify STV:
"Additionally, an RFC may have secondary votes, which are used to decide
implementation details. Such votes may have more than two voting options
and may be decided by simple plurality. This means that the voting option
with the most votes wins. If there are multiple options with the most
number of votes, it is left at the discretion of the RFC author to choose
one of them."

I'm not saying that I agree or disagree with the changes you propose, but I
think that all RFCs should follow the rules that are laid out. Those rules
were last changed by an RFC which also required a 2/3 majority (
https://wiki.php.net/rfc/abolish-narrow-margins), so if you want to change
the requirements to accept an RFC, you should propose them and they should
be accepted before proposing a RFC which does not abide to these
requirements.

Regards,
Pedro



> Hi,
>
> Out of Banjamin's suggestion[1], I've updated the Shorter Attribute
> Syntax Change RFC to reflect that process:
>
> https://wiki.php.net/rfc/shorter_attribute_syntax_change
>
> Patches and comments welcome.
>
> FWIW, this has an excemption from the RM Sara as per [2]:
>
> > […]
>
>
> cheers,
> Derick
>
> [1] https://externals.io/message/111218#111261
> [2] https://externals.io/message/111286#111286
>
> --
> PHP 7.4 Release Manager
> Host of PHP Internals News: https://phpinternals.news
> Like Xdebug? Consider supporting me: https://xdebug.org/support
> https://derickrethans.nl | https://xdebug.org | https://dram.io
> twitter: @derickr and @xdebug
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

## #111333 — Paul M. Jones — 2020-08-05T01:53:33+00:00

URL: https://externals.io/message/111312#111333 · In reply to: #111332

Hi all,

> 
> 
> I'd like to reinforce the idea that this RFC (as all RFCs) needs a Yes/No
> primary vote which should attain a 2/3 majority to pass. As it was the case
> with https://wiki.php.net/rfc/shorter_attribute_syntax, it had a primary
> vote asking "Are you okay with re-voting on the attribute syntax for PHP
> 8.0?" and that vote passed with 50 to 8.
> 
> The primary vote on this RFC could be the exact same question, but I
> believe the primary vote needs to be there. Without this primary vote, we
> could be enacting a change that only (with 4 options) 25%+1 voters support,
> which is clearly insufficient. However, if 2/3 of the voters agree that
> something needs to change, they are also accepting that the change may not
> be the one they prefer.

Hear, hear. If this RFC *must* go to a vote (and that is not a given), then adding a primary vote along the lines of "Are you okay with re-voting on the attribute syntax for PHP 8.0?" would go a long way toward alleviating the "vote until the voters get it 'right'" problem.


-- 
Paul M. Jones
pmjones@pmjones.io
http://paul-m-jones.com

Modernizing Legacy Applications in PHP
https://leanpub.com/mlaphp

Solving the N+1 Problem in PHP
https://leanpub.com/sn1php

---

## #111334 — tyson andre — 2020-08-05T01:57:37+00:00

URL: https://externals.io/message/111312#111334 · In reply to: #111312

Hi Derick,

> Out of Banjamin's suggestion[1], I've updated the Shorter Attribute 
> Syntax Change RFC to reflect that process:
> 
> https://wiki.php.net/rfc/shorter_attribute_syntax_change
> 
> Patches and comments welcome.

1. I feel like "Changes the lexing of **remaining** tokens" should also be included in the table following it - that's a major difference between `#[`(Yes) and each of the other proposals (No).
    The last time a substantial lexing change (that affected the following tokens, not just the tokens in question) happened was https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes , but flexible heredoc is rare in practice and a project using it would almost always need to drop support for 7.2.
    I expect attributes to be used much, much more frequently than flexible heredoc, and to break in subtler ways.
    Projects such as php-parser would be affected by the change to lexing, and would either have to force users to specify the php major version or to always emulate 8.0's lexing if `#[` was encountered in a `T_COMMENT` token.

    My earlier objections to `#[` were https://externals.io/message/111218#111239

    To add to that, the benefit of forwards compatibility is also a drawback in some ways for the next few years (or longer, if you include OSes that unofficially backport security patches)
    A developer running php7 could run `php --syntax-check` locally on a file containing attributes
    and assume it'd work in php 8 when deployed to a php 8 environment or when publishing a library to packagist.
    (e.g. `#[DeprecationReason('This won't work because X')]` has a single quote after `won` terminating a string literal, resulting in a parse error only affecting php 8)

    Better tooling would help to avoid that, but better tooling isn't universal.
2. This RFC mentions objections to `@@` but not objections to other syntaxes.
    Summarizing/Linking the main arguments for/against all 4+ proposed syntaxes in an appendix of the RFC (with some reasonable length limit) would help in making an informed vote.

    There have been over 50 emails so far in https://externals.io/message/111300 and https://externals.io/message/111312

Thanks,
- Tyson

---

## #111335 — tyson andre — 2020-08-05T02:27:24+00:00

URL: https://externals.io/message/111312#111335 · In reply to: #111324

Hi Derick,

> Hi Derick,
>
> I don't agree with the main argument put forward in this RFC:
>
> > […]
>
> Attributes are not a standalone statement or declaration; they are
> metadata *on* a declaration. They cannot stand alone, but always
> modify the following declaration, just as public and static modify
> a method, or a type declaration modifies a parameter or property.
>
> Modifying declarations (e.g. for visibility and type) do not have an
> ending symbol. For example, we don't write something like:
>
>     [public] function foo([int] $bar) {}
>
> With the @@ syntax attributes a treated consistently with type and
> visibility declarations:
>
>     @@Jit
>     public function foo(@@Deprecated int $bar) {}
>
> So there is nothing inconsistent about not having a termination
> symbol - this is in harmony with visibility and type declarations in
> PHP, as well as the attribute syntax used by a majority of C family
> languages. [1]
>
> When it comes to supporting attribute grouping, I actually consider
> this a downside of the #[], @[], and <<>> syntaxes. It complicates
> the internal implementation, and makes it so developers have to
> choose between two different syntaxes when adding more than one
> attribute. In real-world use cases the @@ syntax is just as or even
> more concise without the extra parser/compiler complexity:
>
>     #[Attr1, Attr2] # 15 chars
>
>     @@Attr1 @@Attr2 # 15 chars
>
>     # 4 lines, 53 chars not counting whitespace
>     @[
>         AttrWithParam("foobar"),
>         SomeOtherAttr("fizzbuzz"),
>     ]
>
>     # 2 lines, 52 chars
>     @@AttrWithParam("foobar")
>     @@SomeOtherAttr("fizzbuzz")
>
> I agree that we want the best syntax, not necessarily the best
> **looking** syntax. I still believe that the @@ syntax offers the best
> balance here. It's familiar, concise without additional complexity,
> and doesn't break useful syntax the way @[] and #[] do.
>
> Kind regards, 
> Theodore

I agree with Theodore's points, including that this is metadata on a declaration, not a declaration itself.

This RFC has proposed that the lack of a closing delimiter might get in the way of future language changes,
but has not given examples of hypothetical syntax extensions that would cause future conflict
and that it'd be impossible to resolve/avoid the ambiguity.
(e.g. Java has managed with `@AttributeName` and optional arguments in parameters, classes, properties, methods, etc.)

PHP already has a lot of places where there is no closing delimiter, even where you'd want/expect one,
so I wouldn't call a lack of closing delimiter unique.
e.g. the below example is parsed as `clone((new stdClass())->foo)`,
because parenthesis aren't part of `clone`.

```
php > clone(new stdClass())->foo;
Notice: Undefined property: stdClass::$foo in php shell code on line 1
Warning: Uncaught Error: __clone method called on non-object in php shell code:1
```

Thanks,
- Tyson

---

## #111336 — Levi Morrison via internals — 2020-08-05T02:59:04+00:00

URL: https://externals.io/message/111312#111336 · In reply to: #111335

> I agree with Theodore's points, including that this is metadata on a declaration, not a declaration itself.

Is this technically true? I haven't peeked at the grammar. I suspect
it is a declaration and not an optional piece of data on a
declaration, like say `public`.

---

## #111337 — Levi Morrison via internals — 2020-08-05T03:00:10+00:00

URL: https://externals.io/message/111312#111337 · In reply to: #111336

On Tue, Aug 4, 2020 at 8:59 PM Levi Morrison
<levi.morrison@datadoghq.com> wrote:
>
> > […]
>
> Is this technically true? I haven't peeked at the grammar. I suspect
> it is a declaration and not an optional piece of data on a
> declaration, like say `public`.

I meant to say "statement", e.g.
I suspect it is a statement and not an optional piece of data on a
statement, like say `public`.

---

## #111338 — tyson andre — 2020-08-05T03:40:55+00:00

URL: https://externals.io/message/111312#111338 · In reply to: #111337

Hi Theodore,

> I meant to say "statement", e.g.
> I suspect it is a statement and not an optional piece of data on a
> statement, like say `public`.

I assume this would boil down to a disagreement on what we mean by statement, and could be clarified by using whatever that definition was instead of "statement" or "declaration".
For example, I might broadly mean that there are expressions, statements, and statement lists in PHP, and statements can be a certain list of node types composed of statements/expressions/nodes (plus standalone expressions), expressions can contain expressions or statement lists, but not statements. (and statement lists can contain 0 or more statements)
(e.g. closures are expressions)

- And then there are nodes that are parts of statements/expressions but neither statements nor expressions, such as parameter declarations
- The php language specification is more complicated than that and my definition would inevitably be over-simplifying, the definition I'd meant was https://github.com/php/php-langspec/blob/master/spec/11-statements.md

By statement, I'd be referring to what parsers generally categorize as statements.
For example, the list of nodes in https://github.com/nikic/PHP-Parser/tree/master/lib/PhpParser/Node/Stmt
- This has changed in the past, e.g. the "throw expression" RFC.
- Still, I'd believe the attributes would be metadata associated with a class statement, a method/function statement, a parameter node, or a closure declaration expression

Regards,
- Tyson

---

## #111339 — Benjamin Eberlei — 2020-08-05T12:20:21+00:00

URL: https://externals.io/message/111312#111339 · In reply to: #111324

On Tue, Aug 4, 2020 at 6:37 PM Theodore Brown <theodorejb@outlook.com>
wrote:

> 
>
> > […]
>
> Hi Derick,
>
> I don't agree with the main argument put forward in this RFC:
>
> > […]
>
> Attributes are not a standalone statement or declaration; they are
> metadata *on* a declaration. They cannot stand alone, but always
> modify the following declaration, just as public and static modify
> a method, or a type declaration modifies a parameter or property.
>
> Modifying declarations (e.g. for visibility and type) do not have an
> ending symbol. For example, we don't write something like:
>
>     [public] function foo([int] $bar) {}
>
> With the @@ syntax attributes a treated consistently with type and
> visibility declarations:
>
>     @@Jit
>     public function foo(@@Deprecated int $bar) {}
>
> So there is nothing inconsistent about not having a termination
> symbol - this is in harmony with visibility and type declarations in
> PHP, as well as the attribute syntax used by a majority of C family
> languages. [1]
>

Attributes are potentially way more complex than a visibility keyword. As
such it is a reasonable requirement to say they should have a unified
ending symbol, or more broadly speaking that attributes should be enclosed
by syntax.

It looks nice for a simple attribute like @@Jit, or for a one without
arguments like the used @@Deprecated, but as soon as there are more than
one, and they each get arguments, enclosing them has its own benefits over
them just standing for themselves.

>
> When it comes to supporting attribute grouping, I actually consider
> this a downside of the #[], @[], and <<>> syntaxes. It complicates
> the internal implementation, and makes it so developers have to
> choose between two different syntaxes when adding more than one
> attribute. In real-world use cases the @@ syntax is just as or even
> more concise without the extra parser/compiler complexity:
>
>     #[Attr1, Attr2] # 15 chars
>
>     @@Attr1 @@Attr2 # 15 chars
>
>     # 4 lines, 53 chars not counting whitespace
>     @[
>         AttrWithParam("foobar"),
>         SomeOtherAttr("fizzbuzz"),
>     ]
>
>     # 2 lines, 52 chars
>     @@AttrWithParam("foobar")
>     @@SomeOtherAttr("fizzbuzz")
>
> I agree that we want the best syntax, not necessarily the best
> **looking** syntax. I still believe that the @@ syntax offers the best
> balance here. It's familiar, concise without additional complexity,
> and doesn't break useful syntax the way @[] and #[] do.
>

Yes, we have been doing this for 20 years, adding annotations enclosed with
/** and */ with each enclosing on its own line for the most part. We even
added stars in front of every inbetween line.

we are stepping into unchartered territory here with @@ by our standards as
PHP community. Using "C familiy" as an argument that they made @ work does
not mean much, because the language itself is just the "interface" to the
implementation, each C family language probably has vastly different
parsers, concerns and approaches. It should be right for PHP.


> Kind regards,
> Theodore
>
> [1]:
> https://wiki.php.net/rfc/shorter_attribute_syntax#comparison_to_other_languages
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

## #111340 — Derick Rethans — 2020-08-05T13:12:50+00:00

URL: https://externals.io/message/111312#111340 · In reply to: #111336

> > […]
> 
> Is this technically true? I haven't peeked at the grammar. I suspect
> it is a declaration and not an optional piece of data on a
> declaration, like say `public`.

IMO this is irrelevant anyway. An attribute isn't just a keyword like 
public, or int. It is *only* an attribute **because** it preceded by a 
specific token; this makes it not just a declaration.

cheers,
Derick

-- 
PHP 7.4 Release Manager
Host of PHP Internals News: https://phpinternals.news
Like Xdebug? Consider supporting me: https://xdebug.org/support
https://derickrethans.nl | https://xdebug.org | https://dram.io
twitter: @derickr and @xdebug

---

## #111341 — Derick Rethans — 2020-08-05T13:13:51+00:00

URL: https://externals.io/message/111312#111341 · In reply to: #111332

> I'd like to reinforce the idea that this RFC (as all RFCs) needs a 
> Yes/No primary vote which should attain a 2/3 majority to pass.

I'll make that clear in the RFC, that was obviously my intention.

cheers,
Derick

-- 
PHP 7.4 Release Manager
Host of PHP Internals News: https://phpinternals.news
Like Xdebug? Consider supporting me: https://xdebug.org/support
https://derickrethans.nl | https://xdebug.org | https://dram.io
twitter: @derickr and @xdebug

---

## #111342 — Rowan Tommins — 2020-08-05T14:03:52+00:00

URL: https://externals.io/message/111312#111342 · In reply to: #111339

>
> It looks nice for a simple attribute like @@Jit, or for a one without
> arguments like the used @@Deprecated, but as soon as there are more than
> one, and they each get arguments, enclosing them has its own benefits over
> them just standing for themselves.
>


The confusing thing about this argument is that as soon as they have
arguments, attributes will have an ending delimiter _whatever_ syntax we
choose, because nobody has ever proposed removing the parentheses around
the arguments.

Detecting the closing parenthesis requires pairing off any parentheses
inside the argument list, but that's still true of the closing bracket in
@[...]. If we make the closing delimiter some random combination like @#]]
then you _still_ need to parse the arguments, because they could contain a
quoted string with those characters in.

While I'm generally in favour of delimited syntaxes, I'm struggling to see
the difference in value between "parentheses are mandatory even if there
are zero arguments" and "the syntax includes an extra pair of outer
brackets".

With no parameters:
@@Foo()
@(Foo)
@[Foo]
@[Foo]@

With complex parameters:
@@Foo('hello @@ world', (1+2)*3)
@(Foo('hello @@ world', (1+2)*3))
@[Foo('hello @[ world ]', [1,2,3])]
@[Foo('hello @[ world ]@ again', [1,2,3])]@

Regards,
-- 
Rowan Tommins
[IMSoP]

---

## #111343 — Theodore Brown — 2020-08-05T16:46:31+00:00

URL: https://externals.io/message/111312#111343 · In reply to: #111339

> 
> > […]
>
> Attributes are potentially way more complex than a visibility keyword.
> As such it is a reasonable requirement to say they should have a
> unified ending symbol, or more broadly speaking that attributes should
> be enclosed by syntax.

Hi Benjamin,

Yes, attributes that take arguments are more complex than a
visibility keyword. Union types can also be more complex.
Nevertheless it is consistent for these declaration modifiers to
not have an ending symbol.

> It looks nice for a simple attribute like @@Jit, or for a one without
> arguments like the used @@Deprecated, but as soon as there are more
> than one, and they each get arguments, enclosing them has its own
> benefits over them just standing for themselves.

Can you clarify what benefits there are to enclosing them as soon as
there is more than one attribute with arguments? From my perspective
this just adds needless complexity without being more concise than
the @@ syntax.

To me it also looks somewhat strange and less readable to require
both a closing parenthesis and a closing bracket when an attribute
has arguments:

    #[MyAttr(
        "some value",
        [1, 2, 3],
        namedArg: true,
    )]

    # vs.

    @@MyAttr(
        "some value",
        [1, 2, 3],
        namedArg: true,
    )

> > […]
> 
> Yes, we have been doing this for 20 years, adding annotations enclosed
> with /** and */ with each enclosing on its own line for the most part.
> We even added stars in front of every inbetween line.
> 
> we are stepping into unchartered territory here with @@ by our
> standards as PHP community. Using "C familiy" as an argument that
> they made @ work does not mean much, because the language itself is
> just the "interface" to the implementation, each C family language
> probably has vastly different parsers, concerns and approaches. It
> should be right for PHP.

I agree that we should pick the syntax that is right for PHP. But how
are the #[] and @[] alternatives a better fit for the language than
@@, given that they break useful syntax, while @@ isn't useful for
anything?

It seems like on the one hand the RFC is arguing that @@ is worse
because that exact token isn't used by another language, and on the
other hand it is simultaneously being argued that we need to
implement a more verbose syntax for adding vague complexity in
the future that isn't used by any other language. Which is it?

A less vague potential extension is attribute nesting, and @@ is
arguably the best fit for this - one of the motivations for proposing
it was to allow attribute nesting while preserving readable code and
a simple internal implementation.

Best regards,  
Theodore

---

## #111344 — David Rodrigues — 2020-08-05T17:10:08+00:00

URL: https://externals.io/message/111312#111344 · In reply to: #111343

A new suggestion: @attr(...). It could be used on future for other syntaxes
and should be supersedes the error supression. So will be a BC exclusively
for @attr() error supression for attr() function. But it is few verbose and
easy to understand. With error supression remotion (9.0?) it could be used
for other new features easily.

Em qua, 5 de ago de 2020 13:46, Theodore Brown <theodorejb@outlook.com>
escreveu:

> On Wed, Aug 5, 2020 at 7:20 AM Benjamin Eberlei <kontakt@beberlei.de>
> wrote:
>
> > […]
>
> Hi Benjamin,
>
> Yes, attributes that take arguments are more complex than a
> visibility keyword. Union types can also be more complex.
> Nevertheless it is consistent for these declaration modifiers to
> not have an ending symbol.
>
> > […]
>
> Can you clarify what benefits there are to enclosing them as soon as
> there is more than one attribute with arguments? From my perspective
> this just adds needless complexity without being more concise than
> the @@ syntax.
>
> To me it also looks somewhat strange and less readable to require
> both a closing parenthesis and a closing bracket when an attribute
> has arguments:
>
>     #[MyAttr(
>         "some value",
>         [1, 2, 3],
>         namedArg: true,
>     )]
>
>     # vs.
>
>     @@MyAttr(
>         "some value",
>         [1, 2, 3],
>         namedArg: true,
>     )
>
> > […]
>
> I agree that we should pick the syntax that is right for PHP. But how
> are the #[] and @[] alternatives a better fit for the language than
> @@, given that they break useful syntax, while @@ isn't useful for
> anything?
>
> It seems like on the one hand the RFC is arguing that @@ is worse
> because that exact token isn't used by another language, and on the
> other hand it is simultaneously being argued that we need to
> implement a more verbose syntax for adding vague complexity in
> the future that isn't used by any other language. Which is it?
>
> A less vague potential extension is attribute nesting, and @@ is
> arguably the best fit for this - one of the motivations for proposing
> it was to allow attribute nesting while preserving readable code and
> a simple internal implementation.
>
> Best regards,
> Theodore
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

Next page: https://externals.io/message/111312.md?page=2
