Menu

Error Identifier: constructor.unusedParameterFlow

← Back to constructor.*

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 Foo
{
	public function __construct(int $input)
	{
		while (rand(0, 1)) {
			$input = $input + 1;
		}
	}
}

Why is it reported? #

The constructor’s parameter $input is read — but only by $input = $input + 1, whose result no code ever observes. The parameter’s value feeds a closed computation that produces nothing.

This is different from constructor.unusedParameter, where the parameter is never read at all. Here the value flows through further computation, but that computation is itself dead, so the parameter has no effect on the object.

This only applies to non-promoted parameters. Constructor-promoted parameters (those with visibility keywords like public, protected, or private) are excluded because they initialize properties. Parameters referenced by a @phpstan-assert tag or a conditional return type are also not reported.

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

How to fix it #

Remove the parameter and the dead computation if the result is not needed:

-	public function __construct(int $input)
+	public function __construct()
 	{
-		while (rand(0, 1)) {
-			$input = $input + 1;
-		}
 	}

Or promote the parameter to a property if the value should be kept:

-	public function __construct(int $input)
+	public function __construct(private int $input)
 	{
-		while (rand(0, 1)) {
-			$input = $input + 1;
-		}
 	}

How to ignore this error #

You can use the identifier constructor.unusedParameterFlow to ignore this error using a comment:

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

Rules that report this error #

  • PHPStan\Rules\Classes\UnusedConstructorParametersRule [1]
  • PHPStan\Rules\Functions\UnusedFunctionParametersRule [1]
  • PHPStan\Rules\Methods\UnusedMethodParametersRule [1]
Theme
A
© 2026 PHPStan s.r.o.