Menu

← Back to staticProperty.*

Error Identifier: staticProperty.nonObject

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);

function doFoo(int|string $value): void
{
    echo $value::$foo;
}

Why is it reported? #

The code attempts to access a static property on a value that is not an object or a class string. Static properties can only be accessed on class types. Accessing a static property on a non-object type such as int, float, bool, or a non-class string results in a fatal error at runtime.

How to fix it #

Ensure the variable holds an object or class-string type before accessing static properties:

 <?php declare(strict_types = 1);
 
-function doFoo(int|string $value): void
+function doFoo(Foo $value): void
 {
     echo $value::$foo;
 }

How to ignore this error #

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

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

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.