Menu

← Back to property.*

Error Identifier: property.staticAccess

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 int $value = 42;
}

echo Foo::$value;

Why is it reported? #

The code accesses an instance property using static syntax (ClassName::$property). The property $value is declared as an instance property (non-static), so it belongs to individual objects, not to the class itself. Accessing it statically is incorrect and will cause a runtime error.

How to fix it #

Access the property on an instance of the class:

-echo Foo::$value;
+$foo = new Foo();
+echo $foo->value;

If the property should be shared across all instances, declare it as static:

 class Foo
 {
-	public int $value = 42;
+	public static int $value = 42;
 }

How to ignore this error #

You can use the identifier property.staticAccess to ignore this error using a comment:

// @phpstan-ignore property.staticAccess
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: property.staticAccess

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.