Menu

← Back to deadCode.*

Error Identifier: deadCode.unreachable

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(): int
{
	return 1;
	echo 'unreachable';
}

Why is it reported? #

The statement after return can never be executed. The return statement unconditionally transfers control out of the function, making any code following it in the same block dead code. This usually indicates a logic error or leftover code from refactoring.

The same applies to other control flow statements that always terminate, such as throw, exit, continue, or break.

How to fix it #

Remove the unreachable code:

 function doFoo(): int
 {
 	return 1;
-	echo 'unreachable';
 }

If the code should execute, restructure the logic so it runs before the return:

 function doFoo(): int
 {
+	echo 'this should run';
 	return 1;
-	echo 'unreachable';
 }

How to ignore this error #

You can use the identifier deadCode.unreachable to ignore this error using a comment:

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

Rules that report this error #

  • PHPStan\Rules\DeadCode\UnreachableStatementRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.