Menu

← Back to property.*

Error Identifier: property.readOnlyStatic

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);

class Foo
{
	public static readonly int $count;
}

Why is it reported? #

PHP does not allow a property to be both readonly and static. The readonly modifier is designed for instance properties to ensure they are assigned only once during object construction. Static properties belong to the class itself rather than to individual instances, and PHP does not support readonly semantics for them. Combining the two modifiers results in a compile-time error.

How to fix it #

If the property should be a readonly instance property, remove the static modifier:

 <?php declare(strict_types = 1);
 
 class Foo
 {
-	public static readonly int $count;
+	public readonly int $count;
 }

If the property should be a static class property, remove the readonly modifier:

 <?php declare(strict_types = 1);
 
 class Foo
 {
-	public static readonly int $count;
+	public static int $count;
 }

If the goal is to have a class-level constant that cannot be changed, use a class constant instead:

 <?php declare(strict_types = 1);
 
 class Foo
 {
-	public static readonly int $count;
+	public const int COUNT = 0;
 }

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\Properties\ReadOnlyPropertyRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.