Menu

← Back to attribute.*

Error Identifier: attribute.unresolvableReturnType

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);

#[\Attribute]
class MyAttribute
{
    /**
     * @template T
     * @param T $value
     * @return T
     */
    public function __construct(public mixed $value)
    {
    }
}

#[MyAttribute(value: 'hello')]
class Foo {}

Why is it reported? #

The constructor of the attribute class uses generic template types in its return type, but PHPStan cannot resolve those template types based on the arguments passed in the attribute. This typically happens when the constructor’s return type contains a template type parameter that cannot be inferred from the provided arguments.

Since PHP attributes are instantiated by the runtime with limited context, unresolvable template types in the constructor’s return type indicate a potential issue with the generic type definition.

How to fix it #

The unresolvable template type is usually a symptom of a not-precise-enough type being passed to the constructor. Pass a more specific type so that PHPStan can resolve the template:

-#[MyAttribute(value: 'hello')]
+#[MyAttribute(value: new ConcreteValue('hello'))]
 class Foo {}

If the template type on the constructor is not needed, simplify the type signature:

 #[\Attribute]
 class MyAttribute
 {
-    /**
-     * @template T
-     * @param T $value
-     * @return T
-     */
-    public function __construct(public mixed $value)
+    public function __construct(public string $value)
     {
     }
 }

How to ignore this error #

You can use the identifier attribute.unresolvableReturnType to ignore this error using a comment:

// @phpstan-ignore attribute.unresolvableReturnType
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: attribute.unresolvableReturnType

Rules that report this error #

  • PHPStan\Rules\Classes\ClassAttributesRule [1]
  • PHPStan\Rules\Classes\ClassConstantAttributesRule [1]
  • PHPStan\Rules\Classes\InstantiationRule [1]
  • PHPStan\Rules\Constants\ConstantAttributesRule [1]
  • PHPStan\Rules\EnumCases\EnumCaseAttributesRule [1]
  • PHPStan\Rules\Functions\ArrowFunctionAttributesRule [1]
  • PHPStan\Rules\Functions\CallCallablesRule [1]
  • PHPStan\Rules\Functions\CallToFunctionParametersRule [1]
  • PHPStan\Rules\Functions\CallUserFuncRule [1]
  • PHPStan\Rules\Functions\ClosureAttributesRule [1]
  • PHPStan\Rules\Functions\FunctionAttributesRule [1]
  • PHPStan\Rules\Functions\ParamAttributesRule [1]
  • PHPStan\Rules\Methods\CallMethodsRule [1]
  • PHPStan\Rules\Methods\CallStaticMethodsRule [1]
  • PHPStan\Rules\Methods\MethodAttributesRule [1]
  • PHPStan\Rules\Properties\PropertyAttributesRule [1]
  • PHPStan\Rules\Properties\PropertyHookAttributesRule [1]
  • PHPStan\Rules\Traits\TraitAttributesRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.