Menu

Error Identifier: closure.unusedUseFlow

← Back to closure.*

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

function doFoo(int $input): \Closure
{
	return function () use ($input): void {
		while (rand(0, 1)) {
			$input = $input + 1;
		}
	};
}

Why is it reported? #

The closure imports $input by value through the use clause, and that value is read — but only by $input = $input + 1, whose result no code ever observes. The imported value feeds a closed computation that produces nothing.

This is different from closure.unusedUse, where the imported variable is never read at all. Here the value flows through further computation, but that computation is itself dead, so importing the variable has no effect. This usually points to a logic error where the imported value was meant to be used.

This rule is part of PHPStan’s dead code analysis. It is reported at rule level 1 and above, and is currently part of Bleeding Edge.

How to fix it #

Use the imported value for something observable if that was the intent:

 	return function () use ($input): void {
 		while (rand(0, 1)) {
 			$input = $input + 1;
 		}
+		echo $input;
 	};

Or remove the variable from the use clause and the dead computation:

-	return function () use ($input): void {
-		while (rand(0, 1)) {
-			$input = $input + 1;
-		}
+	return function (): void {
 	};

How to ignore this error #

You can use the identifier closure.unusedUseFlow to ignore this error using a comment:

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

Rules that report this error #

  • PHPStan\Rules\Functions\UnusedClosureUsesRule [1]
Theme
A
© 2026 PHPStan s.r.o.