Error Identifier: paramOut.unusedType
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);
/**
* @param-out int|string $result
*/
function compute(mixed &$result): void
{
$result = 42;
}
Why is it reported? #
The @param-out type annotation declares a union type for a by-reference parameter, but one of the types in the union is never actually assigned to the parameter. PHPStan analyzes all code paths in the function and determines that a part of the declared output type is too wide because it is never used. This indicates that the @param-out annotation is more permissive than what the function actually produces.
How to fix it #
Narrow the @param-out type to only include the types that are actually assigned to the parameter.
<?php declare(strict_types = 1);
/**
- * @param-out int|string $result
+ * @param-out int $result
*/
function compute(mixed &$result): void
{
$result = 42;
}
How to ignore this error #
You can use the identifier paramOut.unusedType to ignore this error using a comment:
// @phpstan-ignore paramOut.unusedType
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: paramOut.unusedType
Rules that report this error #
- PHPStan\Rules\TooWideTypehints\TooWideArrowFunctionReturnTypehintRule [1]
- PHPStan\Rules\TooWideTypehints\TooWideClosureReturnTypehintRule [1]
- PHPStan\Rules\TooWideTypehints\TooWideFunctionParameterOutTypeRule [1]
- PHPStan\Rules\TooWideTypehints\TooWideFunctionReturnTypehintRule [1]
- PHPStan\Rules\TooWideTypehints\TooWideMethodParameterOutTypeRule [1]
- PHPStan\Rules\TooWideTypehints\TooWideMethodReturnTypehintRule [1]
- PHPStan\Rules\TooWideTypehints\TooWidePropertyTypeRule [1]