Menu

← Back to match.*

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

/**
 * @param 1|2|3 $i
 */
function doFoo(int $i): void
{
	match ($i) {
		'foo' => 'matched foo', // error: Match arm comparison between 1|2|3 and 'foo' is always false.
		default => 'default',
	};
}

Why is it reported? #

The match expression uses strict comparison (===) to evaluate each arm. When the subject type and the arm condition type have no overlap, the comparison will always evaluate to false, meaning the arm can never be matched. In the example above, the parameter $i is typed as 1|2|3 (integers), so comparing it against the string 'foo' will never succeed.

How to fix it #

Remove the unreachable match arm or fix the arm condition to use a value that can actually match the subject.

 /**
  * @param 1|2|3 $i
  */
 function doFoo(int $i): void
 {
 	match ($i) {
-		'foo' => 'matched foo',
+		1 => 'matched one',
 		default => 'default',
 	};
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\Comparison\MatchExpressionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.