diff --git a/Resource/ReflectionClassResource.php b/Resource/ReflectionClassResource.php index 61e8d71d0..06f1d766e 100644 --- a/Resource/ReflectionClassResource.php +++ b/Resource/ReflectionClassResource.php @@ -124,7 +124,7 @@ private function generateSignature(\ReflectionClass $class): iterable if (\PHP_VERSION_ID >= 80000) { $attributes = []; foreach ($class->getAttributes() as $a) { - $attributes[] = [$a->getName(), $a->getArguments()]; + $attributes[] = [$a->getName(), \PHP_VERSION_ID >= 80100 ? (string) $a : $a->getArguments()]; } yield print_r($attributes, true); $attributes = []; @@ -148,7 +148,7 @@ private function generateSignature(\ReflectionClass $class): iterable foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC | \ReflectionProperty::IS_PROTECTED) as $p) { if (\PHP_VERSION_ID >= 80000) { foreach ($p->getAttributes() as $a) { - $attributes[] = [$a->getName(), $a->getArguments()]; + $attributes[] = [$a->getName(), \PHP_VERSION_ID >= 80100 ? (string) $a : $a->getArguments()]; } yield print_r($attributes, true); $attributes = []; @@ -168,7 +168,7 @@ private function generateSignature(\ReflectionClass $class): iterable foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $m) { if (\PHP_VERSION_ID >= 80000) { foreach ($m->getAttributes() as $a) { - $attributes[] = [$a->getName(), $a->getArguments()]; + $attributes[] = [$a->getName(), \PHP_VERSION_ID >= 80100 ? (string) $a : $a->getArguments()]; } yield print_r($attributes, true); $attributes = []; @@ -179,7 +179,7 @@ private function generateSignature(\ReflectionClass $class): iterable foreach ($m->getParameters() as $p) { if (\PHP_VERSION_ID >= 80000) { foreach ($p->getAttributes() as $a) { - $attributes[] = [$a->getName(), $a->getArguments()]; + $attributes[] = [$a->getName(), \PHP_VERSION_ID >= 80100 ? (string) $a : $a->getArguments()]; } yield print_r($attributes, true); $attributes = []; @@ -191,6 +191,12 @@ private function generateSignature(\ReflectionClass $class): iterable continue; } + if (\PHP_VERSION_ID >= 80100) { + $defaults[$p->name] = (string) $p; + + continue; + } + if (!$p->isDefaultValueConstant() || $defined($p->getDefaultValueConstantName())) { $defaults[$p->name] = $p->getDefaultValue(); diff --git a/Tests/Resource/ReflectionClassResourceTest.php b/Tests/Resource/ReflectionClassResourceTest.php index e097205e8..1f3425787 100644 --- a/Tests/Resource/ReflectionClassResourceTest.php +++ b/Tests/Resource/ReflectionClassResourceTest.php @@ -126,6 +126,10 @@ public function provideHashedSignature(): iterable yield [true, 0, '#[Foo]']; } + if (\PHP_VERSION_ID >= 80100) { + yield [true, 0, '#[Foo(new MissingClass)]']; + } + yield [true, 1, 'abstract class %s']; yield [true, 1, 'final class %s']; yield [true, 1, 'class %s extends Exception']; @@ -135,6 +139,11 @@ public function provideHashedSignature(): iterable yield [true, 4, '/** pub docblock */']; yield [true, 5, 'protected $pub = [];']; yield [true, 5, 'public $pub = [123];']; + + if (\PHP_VERSION_ID >= 80100) { + yield [true, 5, '#[Foo(new MissingClass)] public $pub = [];']; + } + yield [true, 6, '/** prot docblock */']; yield [true, 7, 'private $prot;']; yield [false, 8, '/** priv docblock */']; @@ -151,6 +160,11 @@ public function provideHashedSignature(): iterable yield [true, 13, 'protected function prot(#[Foo] $a = []) {}']; } + if (\PHP_VERSION_ID >= 80100) { + yield [true, 13, '#[Foo(new MissingClass)] protected function prot($a = []) {}']; + yield [true, 13, 'protected function prot(#[Foo(new MissingClass)] $a = []) {}']; + } + yield [false, 14, '/** priv docblock */']; yield [false, 15, '']; @@ -162,10 +176,16 @@ public function provideHashedSignature(): iterable yield [false, 9, 'private string $priv;']; } + if (\PHP_VERSION_ID >= 80100) { + yield [true, 17, 'public function __construct(private $bar = new \stdClass()) {}']; + yield [true, 17, 'public function ccc($bar = new \stdClass()) {}']; + yield [true, 17, 'public function ccc($bar = new MissingClass()) {}']; + } + yield [true, 17, 'public function ccc($bar = 187) {}']; yield [true, 17, 'public function ccc($bar = ANOTHER_ONE_THAT_WILL_NEVER_BE_DEFINED_CCCCCCCCC) {}']; yield [true, 17, 'public function ccc($bar = parent::BOOM) {}']; - yield [true, 17, null, static function () { \define('A_CONSTANT_THAT_FOR_SURE_WILL_NEVER_BE_DEFINED_CCCCCC', 'foo'); }]; + yield [\PHP_VERSION_ID < 80100, 17, null, static function () { \define('A_CONSTANT_THAT_FOR_SURE_WILL_NEVER_BE_DEFINED_CCCCCC', 'foo'); }]; } public function testEventSubscriber()