Error Identifier: parameter.unresolvableNativeType
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);
function doFoo(Countable&Traversable&int $value): void // ERROR: Parameter $value has unresolvable native type.
{
}
Why is it reported? #
The parameter’s native type declaration is unresolvable, meaning it creates a type that cannot exist at runtime. This typically happens when an intersection type (&) combines types that are fundamentally incompatible, such as an object type and a scalar type. PHP’s intersection types (available since PHP 8.1) require all members to be class or interface types, and the resulting type must be possible to satisfy.
Since this is a PHP language constraint, the code will fail at runtime.
How to fix it #
Fix the type declaration to use a valid combination of types:
<?php declare(strict_types = 1);
-function doFoo(Countable&Traversable&int $value): void
+function doFoo(Countable&Traversable $value): void
{
}
Or use a union type if multiple unrelated types should be accepted:
<?php declare(strict_types = 1);
-function doFoo(Countable&Traversable&int $value): void
+function doFoo(Countable&Traversable|int $value): void
{
}
Non-ignorable error #
This error cannot be ignored using @phpstan-ignore or the ignoreErrors configuration. Non-ignorable errors indicate code that would cause a crash or a fatal error at runtime, or a fundamental problem in the analysed code that must be addressed.
Rules that report this error #
- PHPStan\Rules\Functions\ExistingClassesInArrowFunctionTypehintsRule [1] [2]
- PHPStan\Rules\Functions\ExistingClassesInClosureTypehintsRule [1] [2]
- PHPStan\Rules\Functions\ExistingClassesInTypehintsRule [1] [2]
- PHPStan\Rules\Methods\ExistingClassesInTypehintsRule [1] [2]
- PHPStan\Rules\Properties\ExistingClassesInPropertyHookTypehintsRule [1] [2]