Menu

← Back to possiblyImpure.*

Error Identifier: possiblyImpure.static

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

/**
 * @phpstan-pure
 */
function getNextId(): int
{
	static $counter = 0;

	return $counter;
}

Why is it reported? #

The function or method is marked as @phpstan-pure but uses a static variable. Static variables persist their value between function calls, which means the function relies on and can modify mutable state. Pure functions must always return the same result for the same inputs and must not depend on hidden state.

How to fix it #

Replace the static variable with a parameter or a different design, or remove the @phpstan-pure annotation if the function intentionally depends on static state:

-/**
- * @phpstan-pure
- */
-function getNextId(): int
+function getNextId(int $counter): int
 {
-	static $counter = 0;
-
 	return $counter;
 }

How to ignore this error #

You can use the identifier possiblyImpure.static to ignore this error using a comment:

// @phpstan-ignore possiblyImpure.static
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: possiblyImpure.static

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.