Replace ugly attribute token #[] to other

php.internals

€– ”k”k

3 years ago
I use @ instead of #[] as attribute token. attribute use whitespace marks are closed. Of course you can start with @@ or #, other. error control use @@ instead of @, add T_SILENCE token new syntax: one attribute: @attribute{WHITESPACE} @otherAttribute(12){WHITESPACE} group attribute: @attribute1(1, 2),attribute2(343, 43)@attibute3(33)[WHITESPACE] current syntax: one attribute: #[attribute()] #[otherAttribute()] group attribute: #[attribute1(1, 2),attribute2(343,),attibute3(33)] below is comparison new syntax: @AttrA@AttrB(112, 334),AttrC @AttrD class A {  @AttrE  @AttrF @AttrG  public $a;  @AttrM public function m1(@AttrParma(1) $c) {} } $ab = @fn(1) fn()=> 1+2; ----------- current syntax: #[AttrA,AttrB(112, 334),AttrC] #[AttrD] class A {  #[AttrE]  #[AttrF] #[AttrG]  public $a;  #[AttrM] public function m1(#[AttrParma(1)] $c) {} } $ab = #[fn(1)] fn()=>1+2; my implemented: https://github.com/chopins/php-src/tree/new-syntax/attribute Other new syntax implemented (Verification of feasibility) : https://github.com/chopins/php-src/blob/php-alternative-syntax/alternative-syntax.md Regards Chopin Xiao

Olle Härstedt

3 years ago
2023-08-23 8:35 GMT+02:00, chopins xiao <chopins.xiao@gmail.com>:
> I use @ instead of #[] as attribute token. attribute use whitespace marks > are closed. Of course you can start with @@ or #, other. > error control use @@ instead of @, add T_SILENCE token > > new syntax: > one attribute: @attribute{WHITESPACE} @otherAttribute(12){WHITESPACE} > group attribute: @attribute1(1, 2),attribute2(343, > 43)@attibute3(33)[WHITESPACE] > > current syntax: > one attribute: #[attribute()] #[otherAttribute()] > group attribute: #[attribute1(1, 2),attribute2(343,),attibute3(33)] > > below is comparison > new syntax: > > @AttrA@AttrB(112, 334),AttrC > @AttrD > class A { >  @AttrE >  @AttrF @AttrG >  public $a; >  @AttrM > public function m1(@AttrParma(1) $c) {} > } > > $ab = @fn(1) fn()=> 1+2; > ----------- > current syntax: > > #[AttrA,AttrB(112, 334),AttrC] > #[AttrD] > class A { >  #[AttrE] >  #[AttrF] #[AttrG] >  public $a; >  #[AttrM] > public function m1(#[AttrParma(1)] $c) {} > } > $ab = #[fn(1)] fn()=>1+2; > > my implemented: > https://github.com/chopins/php-src/tree/new-syntax/attribute > > > Other new syntax implemented (Verification of feasibility) : > https://github.com/chopins/php-src/blob/php-alternative-syntax/alternative-syntax.md > > > Regards > Chopin Xiao >
I think this was debated extensively already. :) It's unlikely to change. Olle

Alexandru Pătrănescu

3 years ago
On Wed, Aug 23, 2023 at 9:36 AM chopins xiao <chopins.xiao@gmail.com> wrote:
> I use @ instead of #[] as attribute token. attribute use whitespace marks > are closed. Of course you can start with @@ or #, other. > error control use @@ instead of @, add T_SILENCE token > > <snip>
> > my implemented: > https://github.com/chopins/php-src/tree/new-syntax/attribute > > > Other new syntax implemented (Verification of feasibility) : > > https://github.com/chopins/php-src/blob/php-alternative-syntax/alternative-syntax.md > > > Regards > Chopin Xiao >
Hey Chopin You can check: https://wiki.php.net/rfc/attributes_v2, that initially implemented it with <<Attribute>> https://wiki.php.net/rfc/shorter_attribute_syntax, that changed the syntax to @@Attribute https://wiki.php.net/rfc/shorter_attribute_syntax_change, that finally changed the syntax to #[Attribute] In time, the last syntax proved to be good, especially when dealing with code that must run as well on PHP versions before PHP 8.0, as it's interpreted there as a comment. All I can see right now are a lot of backward incompatible changes that are unlikely to be accepted with no clear gains. Please consider them, so that there is a clear upgrade path for existing codebase. Regards, Alex

€– ”k”k

3 years ago
but still ugly writing, now recommends using exceptions instead of errors, so should be deprecated error control now PHP already uses a lot of combine marks (more than 30), All marks on the keyboard are already in use just as Dung-Mountain-Code Regards Chopin Xiao ________________________________ 发件人: Alexandru Pătrănescu <drealecs@gmail.com> 发送时间: 2023年8月23日 16:16 收件人: chopins xiao <chopins.xiao@gmail.com> 抄送: internals@lists.php.net <internals@lists.php.net> 主题: Re: [PHP-DEV] Replace ugly attribute token #[] to other On Wed, Aug 23, 2023 at 9:36 AM chopins xiao <chopins.xiao@gmail.com<mailto:chopins.xiao@gmail.com>> wrote: I use @ instead of #[] as attribute token. attribute use whitespace marks are closed. Of course you can start with @@ or #, other. error control use @@ instead of @, add T_SILENCE token <snip> my implemented: https://github.com/chopins/php-src/tree/new-syntax/attribute Other new syntax implemented (Verification of feasibility) : https://github.com/chopins/php-src/blob/php-alternative-syntax/alternative-syntax.md Regards Chopin Xiao Hey Chopin You can check: https://wiki.php.net/rfc/attributes_v2, that initially implemented it with <<Attribute>> https://wiki.php.net/rfc/shorter_attribute_syntax, that changed the syntax to @@Attribute https://wiki.php.net/rfc/shorter_attribute_syntax_change, that finally changed the syntax to #[Attribute] In time, the last syntax proved to be good, especially when dealing with code that must run as well on PHP versions before PHP 8.0, as it's interpreted there as a comment. All I can see right now are a lot of backward incompatible changes that are unlikely to be accepted with no clear gains. Please consider them, so that there is a clear upgrade path for existing codebase. Regards, Alex

Larry Garfield

3 years ago
On Wed, Aug 23, 2023, at 9:10 AM, chopins xiao wrote:
> but still ugly writing, now recommends using exceptions instead of > errors, so should be deprecated error control > now PHP already uses a lot of combine marks (more than 30), All marks > on the keyboard are already in use > just as Dung-Mountain-Code > > > > Regards > Chopin Xiao
I assume there's a language barrier issue here, since I do not know what you're talking about. Exceptions vs Errors has no bearing on the syntax used for attributes in any way. In practice, #[] has proven itself very useful. "Ugly" is a subjective question, but I find it quite readable. Rust uses the same syntax, as well, which is what inspired it. It also took many weeks of discussion and debate to arrive at this consensus. But regardless, there's now tens of thousands of lines of code in the wild that use the current syntax. Changing it now is virtually impossible, even if everyone here agreed that it should be done. So, like it or not, PHP attributes use #[] and will continue to do so. --Larry Garfield