Menu

← Back to staticProperty.*

Error Identifier: staticProperty.nonStaticAccess

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 int $count = 0;
}

$foo = new Foo();
echo $foo->count;

Why is it reported? #

A static property is being accessed using instance (non-static) syntax ($obj->prop). Static properties should be accessed using the class name and the :: operator (ClassName::$prop).

How to fix it #

Use static access syntax:

 <?php declare(strict_types = 1);
 
 $foo = new Foo();
-echo $foo->count;
+echo Foo::$count;

How to ignore this error #

You can use the identifier staticProperty.nonStaticAccess to ignore this error using a comment:

// @phpstan-ignore staticProperty.nonStaticAccess
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: staticProperty.nonStaticAccess

Rules that report this error #

  • PHPStan\Rules\Properties\AccessPropertiesInAssignRule [1]
  • PHPStan\Rules\Properties\AccessPropertiesRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.