Menu

← Back to new.*

Error Identifier: new.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);

/**
 * @template T
 */
class Collection
{
	/** @param T $item */
	public function __construct(private mixed $item)
	{
	}

	/** @return T */
	public function first(): mixed
	{
		return $this->item;
	}
}

function doFoo(): void
{
	$collection = new Collection(); // ERROR: Unable to resolve the return type of constructor of class Collection.
	$collection->first();
}

Why is it reported? #

The constructor of the class uses generic template types in its return type (or the class is generic), but PHPStan cannot resolve those template types from the arguments passed to the constructor. This means that the type information flowing from the new expression into subsequent method calls or property accesses will be incomplete, which may lead to inaccurate analysis.

This typically happens when a generic class constructor expects arguments that help PHPStan infer the template types, but those arguments are missing or have types that are too broad.

How to fix it #

Pass arguments to the constructor that allow PHPStan to resolve the template types:

 <?php declare(strict_types = 1);
 
 function doFoo(): void
 {
-	$collection = new Collection();
+	$collection = new Collection('hello');
 	$collection->first(); // PHPStan now knows this returns string
 }

Or specify the template type explicitly using a PHPDoc @var annotation on the variable:

<?php declare(strict_types = 1);

function doFoo(): void
{
	/** @var Collection<string> $collection */
	$collection = new Collection();
}

How to ignore this error #

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

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