Menu

← Back to void.*

Error Identifier: void.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);

class Formatter
{
	private function format(string $input): void
	{
		$result = strtoupper($input);
	}
}

Why is it reported? #

A function or method returns void, has no side effects, does not throw exceptions, does not modify parameters by reference, and does not have any @phpstan-assert tags. A void function without side effects is useless – it performs computation but discards the result without affecting any observable state.

This is reported for private methods and standalone functions where PHPStan can determine that no side effects occur.

How to fix it #

If the function is supposed to produce a result, return it instead of discarding it:

 <?php declare(strict_types = 1);
 
 class Formatter
 {
-	private function format(string $input): void
+	private function format(string $input): string
 	{
-		$result = strtoupper($input);
+		return strtoupper($input);
 	}
 }

If the function is supposed to have side effects (e.g., writing to a file or modifying external state), add the missing side effect:

 <?php declare(strict_types = 1);
 
 class Formatter
 {
 	private function format(string $input): void
 	{
 		$result = strtoupper($input);
+		echo $result;
 	}
 }

If the function is intentionally impure but PHPStan cannot detect the side effect, mark it explicitly:

 <?php declare(strict_types = 1);
 
 class Formatter
 {
+	/** @phpstan-impure */
 	private function format(string $input): void
 	{
 		$result = strtoupper($input);
 	}
 }

How to ignore this error #

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

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