Error Identifier: generics.unresolvable
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 TSuccess
* @template TError
*/
class Result
{
}
/**
* @extends Result<void, SomeResult::*>
*/
class SomeResult extends Result
{
}
Why is it reported? #
The generic type argument in the @extends, @implements, or @use PHPDoc tag contains a type that cannot be resolved. In this example, SomeResult::* is used as a template argument for the parent class Result, but SomeResult is the class being defined, and the ::* syntax creates a circular reference that cannot be resolved at the point of the class definition.
Common causes of unresolvable types include:
- Self-referencing types that create circular dependencies
- References to class constants or types that do not exist at the point of use
- Invalid type syntax in generic arguments
How to fix it #
Replace the unresolvable type with a concrete, resolvable type:
<?php declare(strict_types = 1);
/**
* @template TSuccess
* @template TError
*/
class Result
{
}
/**
- * @extends Result<void, SomeResult::*>
+ * @extends Result<void, string>
*/
class SomeResult extends Result
{
}
Or use a template type from the class itself if the type needs to remain generic:
<?php declare(strict_types = 1);
/**
* @template TSuccess
* @template TError
*/
class Result
{
}
/**
- * @extends Result<void, SomeResult::*>
+ * @template TError
+ * @extends Result<void, TError>
*/
class SomeResult extends Result
{
}
How to ignore this error #
You can use the identifier generics.unresolvable to ignore this error using a comment:
// @phpstan-ignore generics.unresolvable
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: generics.unresolvable