# Replace ugly attribute token #[] to other

- Thread: https://externals.io/message/120922
- Original archive: https://news-web.php.net/php.internals/120922
- Started by chopins xiao on 2023-08-23T06:35:48+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #120922 — chopins xiao — 2023-08-23T06:35:48+00:00

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

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

---

## #120924 — olleharstedt@gmail.com — 2023-08-23T07:47:44+00:00

URL: https://externals.io/message/120922#120924 · In reply to: #120922

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

---

## #120925 — drealecs@gmail.com — 2023-08-23T08:16:25+00:00

URL: https://externals.io/message/120922#120925 · In reply to: #120922

> 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

---

## #120927 — chopins xiao — 2023-08-23T09:10:44+00:00

URL: https://externals.io/message/120922#120927 · In reply to: #120925

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



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

---

## #120930 — Larry Garfield — 2023-08-23T21:28:35+00:00

URL: https://externals.io/message/120922#120930 · In reply to: #120927

> 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
