Menu

← Back to impure.*

Error Identifier: impure.staticPropertyAccess

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 Counter
{
	public static int $count = 0;
}

/**
 * @phpstan-pure
 */
function getCount(): int
{
	return Counter::$count; // ERROR: Impure static property access in pure function getCount().
}

Why is it reported? #

A function or method marked as @phpstan-pure must not have side effects and must always return the same result for the same inputs. Accessing a static property inside a pure function is considered impure because static properties represent shared mutable state. Their values can change between function calls, which means the function’s return value may differ even when called with the same arguments.

How to fix it #

Pass the value as a parameter instead of reading a static property:

 <?php declare(strict_types = 1);
 
 /**
  * @phpstan-pure
  */
-function getCount(): int
+function getCount(int $count): int
 {
-	return Counter::$count;
+	return $count;
 }

Or remove the @phpstan-pure annotation if the function genuinely needs to access static properties:

 <?php declare(strict_types = 1);
 
-/**
- * @phpstan-pure
- */
 function getCount(): int
 {
 	return Counter::$count;
 }

How to ignore this error #

You can use the identifier impure.staticPropertyAccess to ignore this error using a comment:

// @phpstan-ignore impure.staticPropertyAccess
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: impure.staticPropertyAccess

Rules that report this error #

  • PHPStan\Rules\Pure\PureFunctionRule [1]
  • PHPStan\Rules\Pure\PureMethodRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.