Menu

← Back to if.*

Error Identifier: if.alwaysTrue

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 greet(string $name): void
{
	if (is_string($name)) {
		echo 'Hello, ' . $name;
	}
}

Why is it reported? #

The if condition is always true based on the types and values PHPStan has inferred at that point in the code. This means the if branch will always execute, making the condition redundant. This usually points to an unnecessary check, a logic error, or a misunderstanding of the types involved.

How to fix it #

Remove the redundant condition if the check is unnecessary:

 <?php declare(strict_types = 1);
 
 function greet(string $name): void
 {
-	if (is_string($name)) {
-		echo 'Hello, ' . $name;
-	}
+	echo 'Hello, ' . $name;
 }

If the condition was meant to distinguish between different cases, fix the condition to check what was actually intended:

 <?php declare(strict_types = 1);
 
 function greet(string $name): void
 {
-	if (is_string($name)) {
+	if ($name !== '') {
 		echo 'Hello, ' . $name;
 	}
 }

How to ignore this error #

You can use the identifier if.alwaysTrue to ignore this error using a comment:

// @phpstan-ignore if.alwaysTrue
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: if.alwaysTrue

Rules that report this error #

  • PHPStan\Rules\Comparison\IfConstantConditionRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.