Menu

Error Identifier: return.tooWideBool

← Back to 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);

/** @return bool */
function alwaysTrue(): bool
{
	if (rand(0, 1)) {
		return true;
	}

	return true;
}

Why is it reported? #

The function or method declares bool as its return type, but PHPStan has determined that only one of the two boolean values (true or false) is ever actually returned. The return type is wider than necessary because one of the boolean values is never returned.

In the example above, every code path returns true, so the return type should be narrowed from bool to true.

How to fix it #

Narrow the return type to the specific boolean literal type that is actually returned (PHP 8.2+):

-function alwaysTrue(): bool
+function alwaysTrue(): true
 {
 	if (rand(0, 1)) {
 		return true;
 	}

 	return true;
 }

On older PHP versions, the true standalone type is not available natively. Use a PHPDoc @return tag instead:

-/** @return bool */
+/** @return true */
 function alwaysTrue(): bool

Learn more: PHPDoc Types

If the function is a non-private method that overrides a parent method, the return type may need to stay as bool for compatibility. In that case, configure PHPStan to check protected and public methods using the checkTooWideReturnTypesInProtectedAndPublicMethods option.

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\TooWideTypehints\TooWideArrowFunctionReturnTypehintRule [1]
  • PHPStan\Rules\TooWideTypehints\TooWideClosureReturnTypehintRule [1]
  • PHPStan\Rules\TooWideTypehints\TooWideFunctionParameterOutTypeRule [1]
  • PHPStan\Rules\TooWideTypehints\TooWideFunctionReturnTypehintRule [1]
  • PHPStan\Rules\TooWideTypehints\TooWideMethodParameterOutTypeRule [1]
  • PHPStan\Rules\TooWideTypehints\TooWideMethodReturnTypehintRule [1]
  • PHPStan\Rules\TooWideTypehints\TooWidePropertyTypeRule [1]
Theme
A
© 2026 PHPStan s.r.o.