Menu

← Back to property.*

Error Identifier: property.readOnlyNotSupported

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 readonly int $value; // ERROR: Readonly properties are supported only on PHP 8.1 and later.

	public function __construct(int $value)
	{
		$this->value = $value;
	}
}

Why is it reported? #

The readonly modifier for class properties was introduced in PHP 8.1. Using readonly on a project configured with an earlier PHP version (e.g. PHP 8.0 or PHP 7.4) will result in this error because the code cannot run on the target PHP version.

How to fix it #

If upgrading PHP is possible, update the phpVersion setting in the PHPStan configuration to match the actual PHP version being used:

parameters:
    phpVersion: 80100

If the project must support older PHP versions, remove the readonly modifier and enforce immutability through other means:

 <?php declare(strict_types = 1);
 
 class Foo
 {
-	public readonly int $value;
+	private int $value;

 	public function __construct(int $value)
 	{
 		$this->value = $value;
 	}
+
+	public function getValue(): int
+	{
+		return $this->value;
+	}
 }

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.