diff --git a/stubs/runtime/Attribute.php b/stubs/runtime/Attribute.php index e41f42cfc4..49c794a4ab 100644 --- a/stubs/runtime/Attribute.php +++ b/stubs/runtime/Attribute.php @@ -67,3 +67,10 @@ final class ReturnTypeWillChange { } } + +if (\PHP_VERSION_ID < 80200 && !class_exists('AllowDynamicProperties', false)) { + #[Attribute(Attribute::TARGET_CLASS)] + final class AllowDynamicProperties + { + } +} diff --git a/tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php b/tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php index 90e53baa30..e66e813b02 100644 --- a/tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php +++ b/tests/PHPStan/Rules/Classes/ClassAttributesRuleTest.php @@ -137,4 +137,13 @@ public function testBug7171(): void ]); } + public function testAllowDynamicPropertiesAttribute(): void + { + if (PHP_VERSION_ID >= 80200) { + $this->markTestSkipped('Test requires PHP < 8.2.'); + } + + $this->analyse([__DIR__ . '/data/allow-dynamic-properties-attribute.php'], []); + } + } diff --git a/tests/PHPStan/Rules/Classes/data/allow-dynamic-properties-attribute.php b/tests/PHPStan/Rules/Classes/data/allow-dynamic-properties-attribute.php new file mode 100644 index 0000000000..e17ad37e5b --- /dev/null +++ b/tests/PHPStan/Rules/Classes/data/allow-dynamic-properties-attribute.php @@ -0,0 +1,9 @@ +