Error Identifier: selfOut.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
{
/**
* @phpstan-self-out self<int&string>
*/
public function filterIntegers(): void
{
}
}
Why is it reported? #
The @phpstan-self-out PHPDoc tag contains a type that cannot be resolved. This typically happens when the type includes an impossible intersection (such as int&string, which no value can ever satisfy), references an undefined class, or uses invalid type syntax.
The @phpstan-self-out tag is used to narrow the type of $this after a method call. If the type is unresolvable, PHPStan cannot determine the resulting type of the object.
In the example above, self<int&string> contains the impossible intersection int&string, making the entire type unresolvable.
How to fix it #
Use a valid, resolvable type in the @phpstan-self-out tag:
/**
- * @phpstan-self-out self<int&string>
+ * @phpstan-self-out self<int>
*/
public function filterIntegers(): void
{
}
How to ignore this error #
You can use the identifier selfOut.unresolvableType to ignore this error using a comment:
// @phpstan-ignore selfOut.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: selfOut.unresolvableType
Rules that report this error #
- PHPStan\Rules\PhpDoc\IncompatibleSelfOutTypeRule [1]