Menu

← Back to constructor.*

Error Identifier: constructor.unusedParameter

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 $value, string $unused)
	{
		echo $value;
	}
}

Why is it reported? #

The constructor has a parameter that is never used within the constructor body. In the example above, the parameter $unused is declared but never referenced.

This only applies to non-promoted parameters. Constructor-promoted parameters (those with visibility keywords like public, protected, or private) are excluded because they serve the purpose of initializing properties.

How to fix it #

Remove the unused parameter if it is not needed:

 <?php declare(strict_types = 1);
 
 class Foo
 {
-	public function __construct(int $value, string $unused)
+	public function __construct(int $value)
 	{
 		echo $value;
 	}
 }

Or use the parameter in the constructor body. Alternatively, promote it to a property:

 <?php declare(strict_types = 1);
 
 class Foo
 {
-	public function __construct(int $value, string $unused)
+	public function __construct(int $value, private string $unused)
 	{
 		echo $value;
 	}
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Classes\UnusedConstructorParametersRule [1]
  • PHPStan\Rules\Functions\UnusedClosureUsesRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.