Menu

← Back to assign.*

Error Identifier: assign.staticPropertyProtectedSet

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 protected(set) static int $count = 0;
}

Foo::$count = 5;

Why is it reported? #

The static property uses asymmetric visibility with protected(set), meaning it can be read publicly but can only be written to from within the declaring class or its subclasses. The code is attempting to assign a value to this property from outside the class hierarchy, which violates the write visibility restriction.

Asymmetric visibility for static properties is a PHP 8.4+ feature that allows separate read and write access levels.

How to fix it #

Use a public method on the class to modify the property:

 <?php declare(strict_types = 1);
 
 class Foo
 {
     public protected(set) static int $count = 0;

+    public static function setCount(int $value): void
+    {
+        self::$count = $value;
+    }
 }

-Foo::$count = 5;
+Foo::setCount(5);

Or change the property’s write visibility if external writes are intended:

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

 Foo::$count = 5;

How to ignore this error #

You can use the identifier assign.staticPropertyProtectedSet to ignore this error using a comment:

// @phpstan-ignore assign.staticPropertyProtectedSet
codeThatProducesTheError();

You can also use only the identifier key to ignore all errors of the same type in your configuration file in the ignoreErrors parameter:

parameters:
	ignoreErrors:
		-
			identifier: assign.staticPropertyProtectedSet

Rules that report this error #

  • PHPStan\Rules\Properties\AccessStaticPropertiesInAssignRule [1]
  • PHPStan\Rules\Properties\AccessStaticPropertiesRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.