Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
12.5
Description
The following code is valid. However, if we use attributes with interface constants and methods, syntax errors occur.
Example code:
<?php #[I1] interface I { #[I2(1)] // syntax error occurs public const I_CONST = "interface"; #[I3] // syntax error occurs public function method(#[I4] $param1, #[I5(), I6("test")] $param): void; // syntax error occurs } $refI = new \ReflectionClass(I::class); $sourcesI = [ $refI, $refI->getReflectionConstant('I_CONST'), $refI->getMethod('method'), $refI->getMethod('method')->getParameters()[0], $refI->getMethod('method')->getParameters()[1], ]; foreach ($sourcesI as $r) { $attr = $r->getAttributes(); var_dump(get_class($r), count($attr)); foreach ($attr as $a) { var_dump($a->getName(), $a->getArguments()); } echo "\n"; }
Result:
string(15) "ReflectionClass"
int(1)
string(2) "I1"
array(0) {
}
string(23) "ReflectionClassConstant"
int(1)
string(2) "I2"
array(1)
string(16) "ReflectionMethod"
int(1)
string(2) "I3"
array(0) {
}
string(19) "ReflectionParameter"
int(1)
string(2) "I4"
array(0) {
}
string(19) "ReflectionParameter"
int(2)
string(2) "I5"
array(0) {
}
string(2) "I6"
array(1)
Steps to reproduce:
- Create a PHP project
- Create a new file
- Copy and paste the above example code
Attachments
Issue Links
- links to