Menu

Error Identifier: impureFunction.pure

← Back to impureFunction.*

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-impure */
function add(int $a, int $b): int
{
	return $a + $b;
}

Why is it reported? #

A function is marked as impure (via the @phpstan-impure PHPDoc tag) but does not contain any actual side effects. PHPStan detects that the function has no impure points such as I/O operations, property assignments, global state access, or calls to other impure functions. If a function truly has no side effects, it should not be marked as impure.

How to fix it #

If the function genuinely has no side effects, remove the @phpstan-impure annotation. Optionally mark it as @phpstan-pure instead:

 <?php declare(strict_types = 1);
 
-/** @phpstan-impure */
+/** @phpstan-pure */
 function add(int $a, int $b): int
 {
 	return $a + $b;
 }

Or simply remove the annotation entirely and let PHPStan infer purity:

 <?php declare(strict_types = 1);
 
-/** @phpstan-impure */
 function add(int $a, int $b): int
 {
 	return $a + $b;
 }

How to ignore this error #

You can use the identifier impureFunction.pure to ignore this error using a comment:

// @phpstan-ignore impureFunction.pure
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: impureFunction.pure

Rules that report this error #

  • PHPStan\Rules\Pure\PureFunctionRule [1]
  • PHPStan\Rules\Pure\PureMethodRule [1]
Theme
A
© 2026 PHPStan s.r.o.