# [RFC] [Discussion] Shorter Attribute Syntax Change

- Thread: https://externals.io/message/111218
- Original archive: https://news-web.php.net/php.internals/111218
- Started by Joe Ferguson on 2020-07-28T14:46:38+00:00
- Messages: 47
- RFC: Shorter Attribute Syntax Change (Implemented (PHP 8.0)) — https://externals.io/rfc/shorter_attribute_syntax_change.md
- Page 1 of 2: messages 1 to 25 (25 per page, add `?page=N` to the URL)
- Next page: https://externals.io/message/111218.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

---

## #111218 — Joe Ferguson — 2020-07-28T14:46:38+00:00

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

Hello Internals,

I've been working with Derick Rethans and others (thanks all!) on a Shorter
Attribute Syntax Change RFC which outlines reasons why the "#[]" syntax
would be preferred over the currently agreed upon "@@" syntax for Shorter
Attribute Syntax.

An important part of the research that went into this proposal demonstrates
how "@@" will make handling attributes more difficult for PHP_CodeSniffer
(and similar tools) and shows how the alternative "#[]" syntax is more
friendly for these tools.

You can find the RFC
https://wiki.php.net/rfc/shorter_attribute_syntax_change and I'm happy to
answer any questions as best I can.

-- 
- Joe Ferguson
JoeFerguson.me
osmihelp.org

---

## #111220 — come.chilliet@fusiondirectory.org — 2020-07-28T15:13:43+00:00

URL: https://externals.io/message/111218#111220 · In reply to: #111218

Le Tue, 28 Jul 2020 09:46:38 -0500,
Joe Ferguson <joe@joeferguson.me> a écrit :

> Hello Internals,
> 
> I've been working with Derick Rethans and others (thanks all!) on a Shorter
> Attribute Syntax Change RFC which outlines reasons why the "#[]" syntax
> would be preferred over the currently agreed upon "@@" syntax for Shorter
> Attribute Syntax.
> 
> An important part of the research that went into this proposal demonstrates
> how "@@" will make handling attributes more difficult for PHP_CodeSniffer
> (and similar tools) and shows how the alternative "#[]" syntax is more
> friendly for these tools.
> 
> You can find the RFC
> https://wiki.php.net/rfc/shorter_attribute_syntax_change and I'm happy to
> answer any questions as best I can.
> 

The text uses « instead of <<, it’s confusing.

It should be made clearer what #[ ] has over << >>, which does not cause any BC
 break.

Côme

---

## #111221 — Ben Ramsey — 2020-07-28T15:25:34+00:00

URL: https://externals.io/message/111218#111221 · In reply to: #111220

> 
> 
> Le Tue, 28 Jul 2020 09:46:38 -0500,
> Joe Ferguson <joe@joeferguson.me> a écrit :
> 
> > […]
> 
> The text uses « instead of <<, it’s confusing.
> 
> It should be made clearer what #[ ] has over << >>, which does not cause any BC
> break.
> 
> Côme


I don’t know that it’s valuable to spend time discussing advantages
over `<< >>`. Isn’t it clear from the previous RFC[^1] that `@@` and
`#[ ]` both won out over `<< >>`?

Cheers,
Ben


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

---

## #111222 — Derick Rethans — 2020-07-28T15:50:49+00:00

URL: https://externals.io/message/111218#111222 · In reply to: #111218

> I've been working with Derick Rethans and others (thanks all!) on a 
> Shorter Attribute Syntax Change RFC which outlines reasons why the 
> "#[]" syntax would be preferred over the currently agreed upon "@@" 
> syntax for Shorter Attribute Syntax.

This is an excellent RFC highlighting the important deficiencies of the 
@@ syntax.

I hope you will all read this and also conclude that we can still pick 
this better syntax.

Remember that it is not only about how it looks. It is much more 
important that it is functional and causes the least amount of friction 
in the community.

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

---

## #111223 — Sebastian Bergmann — 2020-07-28T15:54:30+00:00

URL: https://externals.io/message/111218#111223 · In reply to: #111222

Am 28.07.2020 um 17:50 schrieb Derick Rethans:
> This is an excellent RFC highlighting the important deficiencies of the
> @@ syntax.
> 
> I hope you will all read this and also conclude that we can still pick
> this better syntax.
> 
> Remember that it is not only about how it looks. It is much more
> important that it is functional and causes the least amount of friction
> in the community.

Hear, hear.

---

## #111225 — Theodore Brown — 2020-07-28T17:57:34+00:00

URL: https://externals.io/message/111218#111225 · In reply to: #111218

> Hello Internals,
> 
> I've been working with Derick Rethans and others (thanks all!) on a Shorter
> Attribute Syntax Change RFC which outlines reasons why the "#[]" syntax
> would be preferred over the currently agreed upon "@@" syntax for Shorter
> Attribute Syntax.
> 
> An important part of the research that went into this proposal demonstrates
> how "@@" will make handling attributes more difficult for PHP_CodeSniffer
> (and similar tools) and shows how the alternative "#[]" syntax is more
> friendly for these tools.
> 
> You can find the RFC
> https://wiki.php.net/rfc/shorter_attribute_syntax_change and I'm happy to
> answer any questions as best I can.

Hi Joe,

From the perspective of looks alone I don't care much one way or the
other between @@ and #[]. However, I don't find the arguments for #[]
in this RFC very compelling, and it ignores some of the other downsides
of #[] compared to @@ that should be highlighted. Let's go through the
arguments from the RFC:

> It [@@] currently causes a parser conflict

This isn't true now that namespaced names are treated as tokens. The
@@ implementation has been merged into php-src and there is no parser
conflict.

> Various luminaires [sic] consider @@ a joke

Who does this refer to? A random Reddit user?

> Feedback to Derick's tweet (https://twitter.com/derickr/status/1285912223639130114)
> were [sic] overwhelmingly positive

Are you sure? I took a look at the thread and it seems like the
responses were pretty mixed. Some people expressed support for #[],
but almost as many were happier with the @@ syntax. If anything the
majority of responses were neutral or expressing dislike for all the
syntax options.

> It has the distinct possibility to cause further parsing issues

Like what? How is it any more likely to cause parsing issues than the
@ syntax used by the majority of other C family languages?

> Having a closing ] makes it easier to extend Attributes with more syntax

This might be a good argument if there were actually a need to extend
attributes with more syntax. What other languages have found a need for
this? Even Rust doesn't allow additional syntax inside the brackets.

> There is no “end symbol” to make finding occurrences easier,
> including by reading or using regular expressions.

Can you provide an example? When reading code I personally don't find
the ending bracket very helpful - my brain tends to parse it as the
end of an array, not the end of an attribute. Even when using a regex
to search code, the ending bracket doesn't seem very helpful since
arrays can also be passed as attribute arguments. For example, to
match this attribute the regex for @@ is actually simpler than the
one for #[]:

```php
# regex: /@@\w+\(.+\)/
@@Attr([1, 2])

# vs.

# regex: /#\[\w+\(.+\)\]/
#[Attr([1, 2])]
```

> A syntax with a closing demarcation is much easier to back fill with
> tools such as PHPCS.

I'm not sure I understand this. What does it mean to "back fill" a
syntax with PHPCS, and what does a closing demarcation have to do with
it? As a user, I'd expect to have to update PHPCS to work with PHP 8
code - doesn't it have to be updated anyway to correctly support the
syntax for named arguments, union types, the nullsafe operator, match
expression, etc.?

And from a perspective of compatibility with existing tools, couldn't
@@ be considered superior since people can use it in code examples
on a blog without the syntax highlighter treating it as a comment?

> It is a syntax no other language uses.

Rust chose to use #[] even though it wasn't used by any other language.
Does that make it a bad fit for Rust? No. But just because Rust uses
a syntax also doesn't mean it's a good fit for PHP.

@@ fits well with PHP since there is virtually no BC break, and the
syntax is close to the @annotation syntax currently used in docblocks,
so it's easily recognizable for what it is. On the other hand, #[]
would be a larger BC break and can easily be confused for a comment.

Best regards,
Theodore

---

## #111227 — Paul M. Jones — 2020-07-28T18:55:59+00:00

URL: https://externals.io/message/111218#111227 · In reply to: #111225

Hi all,

> 
> 
> > […]
> 
> Are you sure? I took a look at the thread and it seems like the
> responses were pretty mixed.

Let's count. + is "change away from @@ to anything else", - is "stay with @@", ? is hard-to-tell/weak/uncertain/they-all-suck.

Derick Rethans: ++
Rafael Dohms: +?
Alexander Berl: -?
Chris Emerson: --
Tamas Erdelyi: ??
Phili Weinke: ??
Trent: ++
Juriaan Ruitenberg: ++
Mehran: ++
Stephan Hochdorfer: ??
Cees-Jan Kiewiet: ??
Tom Witkowski: ++
Matiss: ++
Henry Paradiz: --
Saif: ??
Paul Redmond: ??
Marco Pivetta: ++
Simon Champion: ??
@eimihar: ??
Brent: +?
Graham Campbell: +?
Dmitri Goosens: ++
Sergej Kurakin: -?
Francis Lavoie: ??
Michael Moravec: ??
John Hunt: ??
Lars Moelleken: ??
Michal Brzuchalski: -?
Kyrre: ??
Steve MacDougall: ++
Agustin Gomes: ??
Mike Rockett: ++
Matias Navarro: ++
Marisa Clardy: ++
Warp Speed: --
WJB: +?
Martijn Minnis: --
Dennis de Best: ??
Damo: ??
SOFTonSOFA: +?
Ashish K. Poudel: +?
Bastien Remy: ??
Matiss: +?
Thierry D.: +?
Ihor Vorotnov: ??
Hugo Alliaume: ??
Juan Millan: +?
Olbaum: +?
Steve Baumann: ??
James Mallison: ??
Marco Deleu: ??
TheGenuinenessSheriff: ++
Golgote: ??

++: 13 definitely prefer changing to something other than @@ (though not necessarily #[])
+?: 10 probably prefer changing to something other than @@ (though not necessarily #[])
??: 23 hard-to-tell/weak/uncertain/they-all-suck
-?: 3 probably prefer to keep @@
--: 4 definitely prefer to keep @@

So, the majority of Twitter respondents in that thread appear to be against @@, and in favor of "something else" (24 to 7).

Having pointed all that out, I note that Twitter is not the voting mechanism here. Further, I opine that "voting repeatedly until the voters get it 'right' and then calling the matter settled for all time" is not how decision-by-voting is supposed to work.

Now, it may be that #[] or <<>> or something else actually is "better" in some sense that cannot be articulated. But if there are no existing technical hurdles to be overcome with the already-voted-on-and-accepted solution of @@, what technically compelling reason can there be to revote?


-- 
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

---

## #111228 — Ben Ramsey — 2020-07-28T19:07:11+00:00

URL: https://externals.io/message/111218#111228 · In reply to: #111227

> 
> 
> Now, it may be that #[] or <<>> or something else actually is "better" in some sense that cannot be articulated. But if there are no existing technical hurdles to be overcome with the already-voted-on-and-accepted solution of @@, what technically compelling reason can there be to revote?


IMO, there is no compelling reason to revote other than the fact that we have no process for what to do in this situation. However, given that we used ranked-choice voting in the last RFC, the logical choice (to me) seems to be: choose the runner-up in the event that the winner is disqualified.

So, if there are extenuating circumstances that result in `@@` being disqualified, we should automatically default to the runner-up in the ranked-choice outcome.

Cheers,
Ben

---

## #111229 — Paul M. Jones — 2020-07-28T19:10:18+00:00

URL: https://externals.io/message/111218#111229 · In reply to: #111228

> 
> 
> > […]
> 
> 
> IMO, there is no compelling reason to revote other than the fact that we have no process for what to do in this situation.

What "situation" is this, exactly? AFICT we have a working implementation using @@, with no technical hurdles to surmount. Or have I missed something that now prevents @@ from working per its RFC?


-- 
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

---

## #111230 — Ben Ramsey — 2020-07-28T19:15:01+00:00

URL: https://externals.io/message/111218#111230 · In reply to: #111229

> 
> 
> > […]
> 
> What "situation" is this, exactly? AFICT we have a working implementation using @@, with no technical hurdles to surmount. Or have I missed something that now prevents @@ from working per its RFC?


The new RFC outlines reasons why `@@` is a sub-optimal choice.

TL;DR:

* current parser conflict (which can be worked around)
* possibility for further (as of yet unknown) parsing issues
* a closing ] makes it easier to extend Attributes with more syntax,
  and at the same time not be at the risk of running into parser
  conflicts
* userland analysis tools have difficulties parsing `@@`


Cheers,
Ben

---

## #111231 — Mark Randall — 2020-07-28T19:38:28+00:00

URL: https://externals.io/message/111218#111231 · In reply to: #111225

> > […]
> 
> This might be a good argument if there were actually a need to extend
> attributes with more syntax. What other languages have found a need for
> this? Even Rust doesn't allow additional syntax inside the brackets.

Just because they haven't, does not mean we won't. Unless there's a good 
reason to do otherwise, we should provide for future flexibility where 
possible.

I previously provided examples of ways in which we might want to extend 
the syntax.

Most things in PHP allow some level of scope restriction, such as 
private or protected. One day we may want to extend annotations to 
include such a feature, such as a protected annotation that can only be 
accessed by the class itself or its descendants.

#[protected MyAttribute(xyz)]


Attributes are not validated when they are encountered, this may be 
something that we wish to allow attributes to opt-in to in future.

#[checked MyAttribute(xyz])


In future we might want to offer APIs that return an array of all of the 
instances (moving the creation up from newInstance) and then tighten up 
the behvaiour for classes which do not exist (because they might belong 
to an optional package, such as debugging or code analysis). This might 
come in the form of something like:

#[optional MyAttribute(xyz)]


Some of these might happen, none of these might happen, something 
completely different might happen.

What is clear is we've got to support Attributes for 20, 30 years, and 
we should leave the door open for easier and cleaner syntax additions if 
there's no compelling reason not to.

--
Mark Randall

---

## #111232 — Paul M. Jones — 2020-07-28T19:39:25+00:00

URL: https://externals.io/message/111218#111232 · In reply to: #111230

> 
> 
> > […]
> 
> 
> The new RFC outlines reasons why `@@` is a sub-optimal choice.

And yet it was the one chosen by the voting process. (Silly voters, making sub-optimal choices!)

The rest of your message reveals what I thought was true: i.e., there are no currently-verified technical barriers to @@. To wit:


> * current parser conflict (which can be worked around)

AFAICT that pre-existing problem has been fixed, so this is a non-issue.


> * possibility for further (as of yet unknown) parsing issues

IOW, imaginary issues, aka FUD.


> * a closing ] makes it easier to extend Attributes with more syntax,  and at the same time not be at the risk of running into parser conflicts

Maybe, maybe not. This has the strongest possibility of becoming a technical argument, but no competing implementation (with a comparative implementation using @@)  has been presented as an example. So as it stands now, this also is imaginary.


> * userland analysis tools have difficulties parsing `@@`

Though it does not seem insurmountable for those userland authors. Also, this is an interesting take: does Internals now defer to userland? If so, maybe it's time to open up voting more widely, so that the whole of userland can be represented more effectively here.

Again, I don't especially care if @@, <<>>, or #[], or something else makes it through. Annotations of some sort seem like a nice idea, and I think they'd be of benefit.

But if we are to make decisions by what is ostensibly a democratic process, we should stick to the voted decisions, instead of re-voting issues until the voters "get it right" according to some implicit and unstated criteria.  (If re-voting over and over is the plan, I've got some RFCs I might like to revisit as well.)


-- 
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

---

## #111233 — Joe Ferguson — 2020-07-28T19:52:20+00:00

URL: https://externals.io/message/111218#111233 · In reply to: #111225

On Tue, Jul 28, 2020 at 12:57 PM Theodore Brown <theodorejb@outlook.com>
wrote:

>
> Hi Joe,
>
> From the perspective of looks alone I don't care much one way or the
> other between @@ and #[]. However, I don't find the arguments for #[]
> in this RFC very compelling, and it ignores some of the other downsides
> of #[] compared to @@ that should be highlighted. Let's go through the
> arguments from the RFC:
>

<snipped here>

Theodore, thanks for your comments, time, and work on the Shorter Attribute
Syntax RFC. I appreciate your feedback and I'm also of the mind where I
don't care based on looks alone. The RFC also notes the @@ issues have been
resolved by the RFC closing at the end of the month.

My motivation for this RFC is based on 2 things:

Firstly, the @@ syntax makes parsing harder (although not impossible) on
CLI tools such as PHPCS. Therefore IMHO internals should make the best
effort to avoid this when possible.

Secondly, I'd like to see internals use this as a point in the future to
avoid this kind of issue where we need to vote on something yet again
instead of taking the runner up in a ranked-choice vote. Originally this
was my main motivation until I saw the issues raised by the PHPCS users.

I don't want this to become an issue of "keep voting until we get the vote
we like" as Paul mentioned. This RFC is my attempt to set a precedent where
internals allows itself to be some measurement more autonomous than it
currently is today. And also to try to make the 8.0 upgrade process a bit
friendlier to our fiends writing userland code.

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

-- 
- Joe Ferguson
JoeFerguson.me
osmihelp.org

---

## #111234 — Marcio Almada — 2020-07-28T19:58:26+00:00

URL: https://externals.io/message/111218#111234 · In reply to: #111233

Hi,

>
> On Tue, Jul 28, 2020 at 12:57 PM Theodore Brown <theodorejb@outlook.com>
> wrote:
>
> > […]
>
> <snipped here>
>
> Theodore, thanks for your comments, time, and work on the Shorter Attribute
> Syntax RFC. I appreciate your feedback and I'm also of the mind where I
> don't care based on looks alone. The RFC also notes the @@ issues have been
> resolved by the RFC closing at the end of the month.
>
> My motivation for this RFC is based on 2 things:
>
> Firstly, the @@ syntax makes parsing harder (although not impossible) on
> CLI tools such as PHPCS. Therefore IMHO internals should make the best
> effort to avoid this when possible.
>
> Secondly, I'd like to see internals use this as a point in the future to
> avoid this kind of issue where we need to vote on something yet again
> instead of taking the runner up in a ranked-choice vote. Originally this
> was my main motivation until I saw the issues raised by the PHPCS users.
>

Is this issue documented somewhere on github or on any other platform?
I'd like to see the discussion and maybe participate in it.

Thanks,
Márcio

---

## #111235 — Peter Cowburn — 2020-07-28T20:46:10+00:00

URL: https://externals.io/message/111218#111235 · In reply to: #111234

(Top posting because... sue me.)

I hereby propose to use @[] syntax for attributes.

No need to vote; it's clearly the best, nay only, real option.

Make it so.

P.S. Sorry for suggesting @@ earlier, I've no idea what I was thinking.
Creating new syntax is HARD!
P.P.S. <3



> Hi,
>
> > […]
> Attribute
> > […]
> been
> > […]
>
> Is this issue documented somewhere on github or on any other platform?
> I'd like to see the discussion and maybe participate in it.
>
> Thanks,
> Márcio
>
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

## #111237 — Theodore Brown — 2020-07-28T21:55:11+00:00

URL: https://externals.io/message/111218#111237

> 
> > […]
> 
> Just because they haven't, does not mean we won't. Unless there's a good
> reason to do otherwise, we should provide for future flexibility where
> possible.
> 
> I previously provided examples of ways in which we might want to extend
> the syntax.

Hi Mark,

I appreciate the examples. I think there are good reasons not to
implement these kind of extensions, at least in this form. I'll reply
to each example below.

> Most things in PHP allow some level of scope restriction, such as
> private or protected. One day we may want to extend annotations to
> include such a feature, such as a protected annotation that can only be
> accessed by the class itself or its descendants.
> 
> #[protected MyAttribute(xyz)]

Given that attributes are metadata, restricting their scope seems
rather pointless, and probably would only encourage their (mis)use
for things they aren't the right solution for. Isn't the whole point
of an attribute to be read by something outside the class? If the
metadata is only for the class itself, class constants with
appropriate visibility can be used instead.

> Attributes are not validated when they are encountered, this may be
> something that we wish to allow attributes to opt-in to in future.
> 
> #[checked MyAttribute(xyz])

I hope if we allow opting into such a feature it won't have to be so
verbose and won't require making checked a new reserved keyword. I
suppose the same thing could be accomplished with a distinct token,
for example:

@@!MyAttribute(xyz)

> In future we might want to offer APIs that return an array of all of the
> instances (moving the creation up from newInstance) and then tighten up
> the behvaiour for classes which do not exist (because they might belong
> to an optional package, such as debugging or code analysis). This might
> come in the form of something like:
> 
> #[optional MyAttribute(xyz)]

Existing attributes are already optional, though, so it's not clear
what value this would add. If we want some attributes to not be
optional, we could add a new syntax for checked attributes like the
previous example.

> Some of these might happen, none of these might happen, something
> completely different might happen.
> 
> What is clear is we've got to support Attributes for 20, 30 years, and
> we should leave the door open for easier and cleaner syntax additions if
> there's no compelling reason not to.

I'm not convinced this approach of additional keywords before an
attribute is the easiest or cleanest way to implement additions. It
seems like it could lead to more BC breaks and unnecessary verbosity
if it encourages adding new keywords. And as you point out, whether
any such additions happen is completely hypothetical right now.

In the present what we do know is that #[] is a bigger BC break than
@@, and that other languages haven't had a need for such syntax
additions in the many years that attributes have been around.

Best regards,  
Theodore

---

## #111238 — Mark Randall — 2020-07-28T23:09:11+00:00

URL: https://externals.io/message/111218#111238 · In reply to: #111237

> I appreciate the examples. I think there are good reasons not to
> implement these kind of extensions, at least in this form. I'll reply
> to each example below.


The problem is your argument comes from a position of... because you 
don't like those examples, we shouldn't make accomodation for them or 
anything like them in future.

Adopting such extensions is a matter for a future RFC, and not for 
preemptively throwing a spanner in the works.

Mark Randall

---

## #111239 — tyson andre — 2020-07-29T00:21:31+00:00

URL: https://externals.io/message/111218#111239 · In reply to: #111218

Hi internals,

For #[, my main objection is the various ways this can change the lexing in a way that is impractical to (efficiently) backfill,
and that the proposed patch doesn't address the fact that the syntax may change the syntax of php 7 code in unexpected ways. 

This syntax would help phpcs with easy examples **in the short term**, when attributes are on a single line,
but would make more complicated refactorings buggy and error-prone unless phpcbf was run in the same major version.
When attributes span multiple lines, the lexing is completely different for `#[]`.
For example, the below syntax would yield false in php 7, but a generator in php 8.
(There's precedent at least - the lexing of heredocs changed in php 7.3 or 7.4)

```
// Aside: This code snippet seems to have an assert failure in the lexer with the patch in the RFC
// Zend/zend_compile.c:1794: zendlex: Assertion `!(executor_globals.exception) || ret == T_ERROR' failed.
function generator() {
    yield #[MyCustomAttribute('
        false;
        // ']function() {};
}
```

And another example which would cause problems for phpcs in php 7 - the comment syntax can cause code to be treated as inline html instead of php tokens.

```
<?php
// This example echoes the rest of the source code in php 7
// and echoes "Test" in php 8.
#[DeprecationReason('reason: <https://some-website/reason?>')]
function main() {}
const APP_SECRET = 'app-secret';
echo "Test\n";
```

I'd posted another example in https://externals.io/message/111101#111133

One way I'd thought of to avoid this ambiguity would be to assert in PHP 8.0 with an `E_COMPILE_ERROR` (or E_COMPILE_WARNING) that:
1. All tokens of the #[...] annotation are on the same line
2. No non-whitespace token follows the ] on the same line.
    It may be permissible to allow other `//` comments or multiple attributes after it on the same line, though.
3. No `?>` substrings within the rest of the line after #[, maybe

Although I'm not sure if others are actually concerned about this ambiguity and these are really artificial examples for code.

As for `<<`, I'm assuming people may have meant `yield <<JIT>> function() {};`,
but `yield` already has a precedence and didn't have issues - otherwise `yield+2;`  could be adding 2 to the result of a yield.
(It's unambiguously `yield(+2);` right now).
I forget how it'd be parsed, but it wouldn't be ambiguous.

As for `@@`, all of its known issues seem to have been resolved,
and there is still the potential for future issues, but I still prefer it over the `#[` implementation in that patch.

P.S. I'd like to note that
1. A lot more discussion has occurred since the initial vote.
2. Since `@@` was obviously passing at the time, fewer voters would put much thought into detailed tradeoffs of `#[`
3. I haven't seen those specific drawbacks to `#[` of potentially significantly changing lexing (not just losing tokens) mentioned,
   but the shorter attributes syntax RFC did seem to mention params were commented out.

One idea I'd have on voting would be to have the exact same 3-way vote, again, and pick the attribute syntax with the same ranked choice procedure.
I assume proponents of `#[` would have similar objections if an RFC with a two-way vote for  `<<>>` and `@@` was started first.

Regards,
- Tyson

---

## #111240 — Benjamin Eberlei — 2020-07-29T01:11:58+00:00

URL: https://externals.io/message/111218#111240 · In reply to: #111218

Hi Joe,

Personally I favor #[] myself, but there has been a vote with a substantial
participation choosing @@. Overturning this democratic outcome should
require **significant** technical arguments, otherwise this RFC would
provide problematic precedent for any RFC to be overturned by arbitrary
revoting.

The arguments the RFC brings forward don't convince me that we should pick
#[] over @@.

1. The parser conflict was my major reason why @@ should not have been
picked from a technical POV. But this issue has been fixed by an
independent improvement since then. These kinds of small problems are found
regularly after RFCs are accepted and are subsequently fixed. The RFC is
formulated as the problem still exists, but it does not. Yes, the namespace
token RFC vote has not yet finished, but there is no chance it will be
rejected at this point.

Since the namespace token RFC is passing, and I have seen the simplicity of
the new parser rules, my opinion has changed to keep pushing for #[] and I
accept the @@ outcome.

2. The phpcs argument also does not convince me.

Summed up it is essentially that a current version of phpcs does not
support parsing @@ or <<>> yet and incorrectly changes code using them,
however for #[] it does nothing because it parses it as a comment. To me
this sounds like a bug in PHPCS. This argument also breaks down completely
on multi line attributes.

Why should we even expect PHPCS to support an unreleased version? If
someone uses PHP 8 code, why do we assume they keep using an old version of
phpcs that does not support PHP 8 yet?

3. We already established that the syntax question is extremely
contentious, and I was getting tons of messages on it on Twitter, Reddit,
Email et al during the initial Attributes RFC. So of course people would be
against @@ (as I am myself), however it had a majority in votes.

For me putting these subjective opinions into the RFC makes the case for
overturning less convincing, because it makes the argument that overturning
a valid democratic vote is somehow OK if you are loud.

The only reason why we change this outcome must be purely technical imho.

4. You cannot write a regex to detect the end symbols for both #[] or <<>>,
because both end symbols are allowed *inside* the attribute syntax already,
so it's not easier to find occurrences with regexes with the other syntaxes:

#[Foo([1 => 2])]
<<Foo(1 >> 4)>>

Simple detection of attributes will always need to grep only for the start
token, and both @@ and #[ are equally unique to find here.

5. For readability an end token would be nicer (which is why i prefer #[]).
But this information was already known during the first vote on the syntax
and rejected by majority.

6. An end token might indeed allow extending attributes with new stuff, but
nobody has brought up this use-case before. No other language has
additional attribute keywords, why is this brought as a positive argument,
when the choice of syntax no other language uses is brought up as a
negative point later?

7. Future potential parsing problems are brought forward for @@, but #
being a comment token makes it likely that #[] will also cause problems.
Tyson has a few examples in his email to this thread.

Other confusing things you can do with #[] for example:

#[Foo( 1 # 1 ] bar
)]
function foo () { }

Which is #[Foo(1)] without comments and line breaks.

---

## #111243 — michal.brzuchalski@gmail.com — 2020-07-29T06:13:00+00:00

URL: https://externals.io/message/111218#111243 · In reply to: #111227

Hi Paul,

wt., 28 lip 2020 o 20:56 Paul M. Jones <pmjones@pmjones.io> napisał(a):

> ...
> Let's count. + is "change away from @@ to anything else", - is "stay with
> @@", ? is hard-to-tell/weak/uncertain/they-all-suck.
> ...
> Michal Brzuchalski: -?
>

Wow. Hold on your horses. I was never in favour for @@ but always against
at least AFAIR.
Where did you get that?

Anyway it should be ++ here


>
> ++: 13 definitely prefer changing to something other than @@ (though not
> necessarily #[])
>

++: 14 definitely prefer changing to something other than @@ (though not
necessarily #[])


> +?: 10 probably prefer changing to something other than @@ (though not
> necessarily #[])
> ??: 23 hard-to-tell/weak/uncertain/they-all-suck
> -?: 3 probably prefer to keep @@
>

-?: 2 probably prefer to keep @@

--: 4 definitely prefer to keep @@
>

 It's hard to rely fully on your statement considering such a mistake.

Cheers,
Michał Marcin Brzuchalski

---

## #111244 — Nikita Popov — 2020-07-29T07:23:46+00:00

URL: https://externals.io/message/111218#111244 · In reply to: #111239

On Wed, Jul 29, 2020 at 2:21 AM tyson andre <tysonandre775@hotmail.com>
wrote:

> Hi internals,
>
> For #[, my main objection is the various ways this can change the lexing
> in a way that is impractical to (efficiently) backfill,
> and that the proposed patch doesn't address the fact that the syntax may
> change the syntax of php 7 code in unexpected ways.
>
> This syntax would help phpcs with easy examples **in the short term**,
> when attributes are on a single line,
> but would make more complicated refactorings buggy and error-prone unless
> phpcbf was run in the same major version.
> When attributes span multiple lines, the lexing is completely different
> for `#[]`.
> For example, the below syntax would yield false in php 7, but a generator
> in php 8.
> (There's precedent at least - the lexing of heredocs changed in php 7.3 or
> 7.4)
>

That's an interesting point. Emulating #[] lexing on older versions will
definitely be a challenge for PHP-Parser. I don't think we should make
concerns of external tooling hold us back too much, but the phpcs argument
really doesn't hold water.

Regards,
Nikita


> ```
> // Aside: This code snippet seems to have an assert failure in the lexer
> with the patch in the RFC
> // Zend/zend_compile.c:1794: zendlex: Assertion
> `!(executor_globals.exception) || ret == T_ERROR' failed.
> function generator() {
>     yield #[MyCustomAttribute('
>         false;
>         // ']function() {};
> }
> ```
>
> And another example which would cause problems for phpcs in php 7 - the
> comment syntax can cause code to be treated as inline html instead of php
> tokens.
>
> ```
> <?php
> // This example echoes the rest of the source code in php 7
> // and echoes "Test" in php 8.
> #[DeprecationReason('reason: <https://some-website/reason?>')]
> function main() {}
> const APP_SECRET = 'app-secret';
> echo "Test\n";
> ```
>
> I'd posted another example in https://externals.io/message/111101#111133
>
> One way I'd thought of to avoid this ambiguity would be to assert in PHP
> 8.0 with an `E_COMPILE_ERROR` (or E_COMPILE_WARNING) that:
> 1. All tokens of the #[...] annotation are on the same line
> 2. No non-whitespace token follows the ] on the same line.
>     It may be permissible to allow other `//` comments or multiple
> attributes after it on the same line, though.
> 3. No `?>` substrings within the rest of the line after #[, maybe
>
> Although I'm not sure if others are actually concerned about this
> ambiguity and these are really artificial examples for code.
>
> As for `<<`, I'm assuming people may have meant `yield <<JIT>> function()
> {};`,
> but `yield` already has a precedence and didn't have issues - otherwise
> `yield+2;`  could be adding 2 to the result of a yield.
> (It's unambiguously `yield(+2);` right now).
> I forget how it'd be parsed, but it wouldn't be ambiguous.
>
> As for `@@`, all of its known issues seem to have been resolved,
> and there is still the potential for future issues, but I still prefer it
> over the `#[` implementation in that patch.
>
> P.S. I'd like to note that
> 1. A lot more discussion has occurred since the initial vote.
> 2. Since `@@` was obviously passing at the time, fewer voters would put
> much thought into detailed tradeoffs of `#[`
> 3. I haven't seen those specific drawbacks to `#[` of potentially
> significantly changing lexing (not just losing tokens) mentioned,
>    but the shorter attributes syntax RFC did seem to mention params were
> commented out.
>
> One idea I'd have on voting would be to have the exact same 3-way vote,
> again, and pick the attribute syntax with the same ranked choice procedure.
> I assume proponents of `#[` would have similar objections if an RFC with a
> two-way vote for  `<<>>` and `@@` was started first.
>
> Regards,
> - Tyson
> --
> 
> To unsubscribe, visit: https://www.php.net/unsub.php

---

## #111246 — someniatko — 2020-07-29T10:44:37+00:00

URL: https://externals.io/message/111218#111246 · In reply to: #111218

Hello Internals,

Here is a small comparison table based on current feedback, maybe it
will bring some objective clarity to the discussion:
(markdown below)

Impact|`@@`|`#[]`
---|---|---
BC break|virtualy nonexistent|slightly broader: `##[` comments are now broken.
Parser|no technical problems by now|no technical problems by now
Extendability|less future-proof, arguably|more future-proof, arguably
Grepability|harder, arguably|easier, arguably (however, consider an
Attribute taking an array `[]` parameter.)
Perception|similar to PHPDoc annotations, more familiar to PHP
devs|more familiar to Rust devs

Other issues are either speculative or insignificant (as for me):
- causing future parsing issues: no evidence
- "backfilling": there is, arguably, no use case for it. Code using
PHP 8 features will target PHP 8 anyway. Code, compatible with both
PHP 7 and PHP 8 would most probably use classic PHPDoc annotations.
- "syntax no other language uses": this is probably insignificant.
- "possibility of @@ moving to @ is near to 0": i am not sure anyone
planned to move @@ to @, and if so, it would be an unnecessary BC
break.

I am personally in favor of `@@`, but just because it looks visually
nicer to me. I see no strong objective reason to favor one over the
other. If you want an ending token, maybe consider `@@Attribute@@`,
personally I like those round-ish shapes :P.


>
> Hello Internals,
>
> I've been working with Derick Rethans and others (thanks all!) on a Shorter
> Attribute Syntax Change RFC which outlines reasons why the "#[]" syntax
> would be preferred over the currently agreed upon "@@" syntax for Shorter
> Attribute Syntax.
>
> An important part of the research that went into this proposal demonstrates
> how "@@" will make handling attributes more difficult for PHP_CodeSniffer
> (and similar tools) and shows how the alternative "#[]" syntax is more
> friendly for these tools.
>
> You can find the RFC
> https://wiki.php.net/rfc/shorter_attribute_syntax_change and I'm happy to
> answer any questions as best I can.
>
> --
> - Joe Ferguson
> JoeFerguson.me
> osmihelp.org

---

## #111247 — Paul M. Jones — 2020-07-29T12:41:43+00:00

URL: https://externals.io/message/111218#111247 · In reply to: #111243

Hi Michal,

> 
> 
> Hi Paul,
> 
> wt., 28 lip 2020 o 20:56 Paul M. Jones <pmjones@pmjones.io> napisał(a):
> 
> > […]
> 
> Wow. Hold on your horses. I was never in favour for @@ but always against
> at least AFAIR.
> Where did you get that?
> 
> Anyway it should be ++ here

Ah yes, clearly a mistake -- my apologies.


> It's hard to rely fully on your statement considering such a mistake.

I encourage you (and everyone sle who is interested!) to go back and check that Twitter thread to see if I have made other errors.

In the absence of them, my conclusion still stands: that is, "the majority of Twitter respondents in that thread appear to be against @@, and in favor of 'something else'."


-- 
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

---

## #111248 — tyson andre — 2020-07-29T16:29:58+00:00

URL: https://externals.io/message/111218#111248 · In reply to: #111218

Hi internals,

I had thought of another alternative syntax - `/** @@MyAttribute */`, which would solve some of the problems I mentioned about `#[`.

```
namespace My\NS;
use Other\MyAttribute;
/**
 * Use @@ or << at the start of a line. (To be determined)
 * Resolve the names in the comment relative to the scope of the function, like the current attribute implementation.
 * @@MyAttribute(expr, expr)
 * Extra *s are allowed
 *** @@AnotherAttribute
 * Tokenizing should continue until a matching ) is found
 * @@YetAnotherAttribute(
 *   expr
 *)
 */
function my_function() {
}
```

Pros:
- Doc comments are already the recommended way to associate information with a named element.
- Most code modifying tools will preserve doc comments
- This can go on the same line as a closure/short arrow function without lexing ambiguity.
- Frameworks can use `Reflection*->getDocComment()` and update their checks to also allow `@@` for attribute-like annotations when run in PHP 7.
   They don't have to repeat both `@@MyAttribute` and `/** @MyAttribute */` or risk it going out of sync
   (Symfony would already have to parse the `use` clauses to find out what `@MyAttribute` resolves to for Symfony attributes)
- Does not affect lexing outside of the doc comment
- I don't believe @@ is common. To minimize the impact on ascii art, this can be initially limited to @@ at the start of a comment line (spaces and `*`s) immediately followed by \ or the start of an identifier

Cons:
- Need to run the lexer twice on a `T_DOC_COMMENT` token, but only if the comment string contains `@@` and is associated with an element.
   Emitting T_DOC_COMMENT_START and T_DOC_COMMENT_END and T_DOC_COMMENT_INNER and T_DOC_COMMENT_ATTRIBUTE
   T_DOC_COMMENT_ATTRIBUTE_ERROR might make this technically feasible (similar to heredoc having complicated logic)
- I prefer `@@` and `<<>>` over this proposal long-term, after php 7.4 support is dropped.
  But I prefer `/** @@MyAttr */` over `#[MyAttr]`.
- Would end up emitting parse errors for some existing code in the second lexer pass.
- Syntax highlighting might be hard to implement in editors, but probably tractable.

I don't remember seeing this proposed before. I believe @@ isn't used by mainstream frameworks in doc comments right now, but correct me if it is.

Thanks,
- Tyson

---

## #111253 — michal.brzuchalski@gmail.com — 2020-07-29T18:40:31+00:00

URL: https://externals.io/message/111218#111253 · In reply to: #111218

Hi Joe,

wt., 28 lip 2020 o 16:47 Joe Ferguson <joe@joeferguson.me> napisał(a):

> Hello Internals,
>
> I've been working with Derick Rethans and others (thanks all!) on a Shorter
> Attribute Syntax Change RFC which outlines reasons why the "#[]" syntax
> would be preferred over the currently agreed upon "@@" syntax for Shorter
> Attribute Syntax.
>
> An important part of the research that went into this proposal demonstrates
> how "@@" will make handling attributes more difficult for PHP_CodeSniffer
> (and similar tools) and shows how the alternative "#[]" syntax is more
> friendly for these tools.
>
> You can find the RFC
> https://wiki.php.net/rfc/shorter_attribute_syntax_change and I'm happy to
> answer any questions as best I can.
>

Thank you for bringing this up.

TIL something new about popular framework templating component which I
wanna share with you.

There is already use of @@ in files with ".php" extension in Blade
templates from Laravel framework.
In Laravel 7.x double @@ is used as an escape sequence allowing template
compiler to passthrough
TypeScript expressions with @decorator() which is described in the
Templating section of manual[1].

I realize that it's not the same cause the double @@ is used here inside
".php" files in HTML mode
and not in PHP code mode but since this feature exist it may cause issues
on a text search lookup
using for eg. grep | sed | awk like tools.

TL;DR
Now please bear in mind that I'm just saying that people from Larevil
community already
can use the same syntax with double "@@name()" in ".php" files but outside
of PHP code context.

[1] https://laravel.com/docs/7.x/blade#blade-and-javascript-frameworks

Cheers,
Michał Marcin Brzuchalski

---

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