Menu

← Back to missingType.*

Error Identifier: missingType.return

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 findUser(int $id)
{
	// ...
}

Why is it reported? #

The function or method has no return type specified, either as a native PHP return type or through a @return PHPDoc tag. Without a return type, PHPStan treats the return value as mixed, which limits its ability to detect type errors at call sites.

How to fix it #

Add a native return type declaration:

-function findUser(int $id)
+function findUser(int $id): ?User
 {
 	// ...
 }

If native return types cannot be used (e.g. for backward compatibility), add a @return PHPDoc tag:

+/** @return User|null */
 function findUser(int $id)
 {
 	// ...
 }

Learn more about return types in PHPDoc Basics and PHPDoc Types.

How to ignore this error #

You can use the identifier missingType.return to ignore this error using a comment:

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

Rules that report this error #

  • PHPStan\Rules\Functions\MissingFunctionReturnTypehintRule [1]
  • PHPStan\Rules\Methods\MissingMethodReturnTypehintRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.