Menu

← Back to impureMethod.*

Error Identifier: impureMethod.pure

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

final class Formatter
{
	/** @phpstan-impure */
	public function format(string $value): string
	{
		return strtoupper($value);
	}
}

Why is it reported? #

A function or method marked as @phpstan-impure declares that it has side effects, but PHPStan’s analysis found no actual side effects in its body. The method does not perform I/O, modify external state, throw exceptions, or call other impure code. Marking a side-effect-free function as impure is misleading – callers cannot benefit from purity optimizations, and the annotation does not match the actual behavior.

How to fix it #

Remove the @phpstan-impure annotation since the method has no side effects:

-/** @phpstan-impure */
+/** @phpstan-pure */
 public function format(string $value): string
 {
 	return strtoupper($value);
 }

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

-/** @phpstan-impure */
 public function format(string $value): string
 {
 	return strtoupper($value);
 }

If the method is intended to have side effects in the future or in subclasses, mark it as @phpstan-pure for now and change the annotation when side effects are introduced.

How to ignore this error #

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

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

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.