Menu

← Back to trait.*

Error Identifier: trait.allowDynamicProperties

Every error reported by PHPStan has an error identifier. Here’s a list of all error identifiers. In PHPStan Pro you can see the error identifier next to each error and filter errors by their identifiers.

Code example #

<?php declare(strict_types = 1);

#[\AllowDynamicProperties]
trait DynamicTrait
{
}

Why is it reported? #

The #[\AllowDynamicProperties] attribute cannot be used with traits. Traits are not instantiated directly and do not own properties in the same way classes do. The attribute only has meaning when applied to a class. PHP will emit a fatal error at runtime when this attribute is used on a trait.

How to fix it #

Remove the attribute from the trait and apply it to the classes that use the trait instead:

 <?php declare(strict_types = 1);
 
-#[\AllowDynamicProperties]
 trait DynamicTrait
 {
 }

+#[\AllowDynamicProperties]
 class Foo
 {
     use DynamicTrait;
 }

Non-ignorable error #

This error cannot be ignored using @phpstan-ignore or the ignoreErrors configuration. Non-ignorable errors indicate code that would cause a crash or a fatal error at runtime, or a fundamental problem in the analysed code that must be addressed.

Rules that report this error #

  • PHPStan\Rules\Traits\TraitAttributesRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.