Menu

← Back to assign.*

Error Identifier: assign.staticPropertyPrivateSet

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

Foo::$count = 5;

Why is it reported? #

The static property uses asymmetric visibility with private(set), meaning it can be read publicly but can only be written to from within the declaring class. The code is attempting to assign a value to this property from outside the class, 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 private(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 private(set) static int $count = 0;
+    public static int $count = 0;
 }

 Foo::$count = 5;

How to ignore this error #

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

// @phpstan-ignore assign.staticPropertyPrivateSet
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.staticPropertyPrivateSet

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.