Error Identifier: property.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);
class UserService
{
/** @var string&int */
private $identifier;
}
Why is it reported? #
The PHPDoc type for a class property contains a type that PHPStan cannot resolve. This typically happens when the type is an intersection of incompatible types (like string&int which no value can ever satisfy), references a misspelled or undefined class, or uses invalid type syntax.
In the example above, string&int is an intersection type that can never exist because no value can be both a string and an int at the same time.
How to fix it #
Correct the PHPDoc type so it references valid, compatible types:
class UserService
{
- /** @var string&int */
+ /** @var string */
private $identifier;
}
If the property should accept multiple types, use a union type instead of an intersection:
class UserService
{
- /** @var string&int */
+ /** @var string|int */
private $identifier;
}
How to ignore this error #
You can use the identifier property.unresolvableType to ignore this error using a comment:
// @phpstan-ignore property.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: property.unresolvableType
Rules that report this error #
- PHPStan\Rules\PhpDoc\IncompatiblePropertyPhpDocTypeRule [1]