-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Treat attribute argument lists like normal argument lists
Allow trailing comma. Syntactically allow unpacking, but forbid it during compilation. The trailing comma test-case is adopted from GH-5796.
- Loading branch information
Showing
5 changed files
with
50 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--TEST-- | ||
Cannot use unpacking in attribute argument list | ||
--FILE-- | ||
<?php | ||
|
||
<<MyAttribute(...[1, 2, 3])>> | ||
class Foo { } | ||
|
||
?> | ||
--EXPECTF-- | ||
Fatal error: Cannot use unpacking in attribute argument list in %s on line %d |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
--TEST-- | ||
Trailing comma in attribute argument list | ||
--FILE-- | ||
<?php | ||
|
||
<<MyAttribute( | ||
"there", | ||
"are", | ||
"many", | ||
"arguments", | ||
)>> | ||
class Foo { } | ||
|
||
$ref = new \ReflectionClass(Foo::class); | ||
$attr = $ref->getAttributes()[0]; | ||
var_dump($attr->getName(), $attr->getArguments()); | ||
|
||
?> | ||
--EXPECT-- | ||
string(11) "MyAttribute" | ||
array(4) { | ||
[0]=> | ||
string(5) "there" | ||
[1]=> | ||
string(3) "are" | ||
[2]=> | ||
string(4) "many" | ||
[3]=> | ||
string(9) "arguments" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters