Error Identifier: parameter.unresolvableType
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);
/**
* @template T
*/
class Collection
{
/**
* @param T<int> $item
*/
public function add(mixed $item): void
{
}
}
Why is it reported? #
The PHPDoc @param (or @param-out) tag for a parameter contains a type that PHPStan cannot resolve. This typically happens when:
- A template type is used with generic parameters it does not support (e.g.
T<int>whenTis a plain template type) - A type alias or reference cannot be resolved
- The type expression is malformed or references undefined types in a way that creates circular or unresolvable definitions
In the example above, T is a template type that does not accept generic parameters, so T<int> is unresolvable.
How to fix it #
Correct the PHPDoc type so that it can be fully resolved:
<?php declare(strict_types = 1);
/**
* @template T
*/
class Collection
{
/**
- * @param T<int> $item
+ * @param T $item
*/
public function add(mixed $item): void
{
}
}
If the template type needs to be constrained, use the @template bound syntax instead:
<?php declare(strict_types = 1);
/**
- * @template T
+ * @template T of int
*/
class Collection
{
/**
- * @param T<int> $item
+ * @param T $item
*/
public function add(mixed $item): void
{
}
}
How to ignore this error #
You can use the identifier parameter.unresolvableType to ignore this error using a comment:
// @phpstan-ignore parameter.unresolvableType
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: parameter.unresolvableType