Menu

← Back to elseif.*

Error Identifier: elseif.alwaysFalse

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 $i): void
{
	if ($i === 1) {
		// ...
	} elseif ($i === 1) {
		// unreachable
	}
}

Why is it reported? #

The elseif condition always evaluates to false, which means the branch can never be entered. This typically happens when the condition was already covered by a previous if or elseif branch, or when the types involved make the condition logically impossible. Code inside this branch is dead code and likely indicates a logic error.

How to fix it #

Fix the condition so it tests something that can actually be true:

 function doFoo(int $i): void
 {
 	if ($i === 1) {
 		// ...
-	} elseif ($i === 1) {
+	} elseif ($i === 2) {
 		// ...
 	}
 }

Or remove the unreachable branch entirely:

 function doFoo(int $i): void
 {
 	if ($i === 1) {
 		// ...
-	} elseif ($i === 1) {
-		// unreachable
 	}
 }

How to ignore this error #

You can use the identifier elseif.alwaysFalse to ignore this error using a comment:

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

Rules that report this error #

  • PHPStan\Rules\Comparison\ElseIfConstantConditionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.