Replace ugly attribute token #[] to other
| From: | chopins xiao | Date: | Wed, 23 Aug 2023 06:35:48 +0000 |
| Subject: | Replace ugly attribute token #[] to other | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-120922@lists.php.net to get a copy of this message | ||
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