Menu

Error Identifier: method.impossibleType

← Back to method.*

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);

class TypeChecker
{
	/** @phpstan-assert-if-true string $value */
	public function isString(mixed $value): bool
	{
		return is_string($value);
	}
}

function doFoo(TypeChecker $checker, int $value): void
{
	if ($checker->isString($value)) {
		echo 'impossible';
	}
}

Why is it reported? #

A method call that acts as a type check always evaluates to false based on the types PHPStan knows at that point. This means the condition can never be satisfied, so the code inside the branch is dead code.

In the example above, $value is typed as int, and TypeChecker::isString() uses @phpstan-assert-if-true string $value to assert the value is a string. Since int and string are incompatible types, the method will always return false.

How to fix it #

Remove the dead branch if the type check is impossible:

 function doFoo(TypeChecker $checker, int $value): void
 {
-	if ($checker->isString($value)) {
-		echo 'impossible';
-	}
+	// $value is always int, no need to check for string
 }

Or fix the parameter type if the check should be meaningful:

-function doFoo(TypeChecker $checker, int $value): void
+function doFoo(TypeChecker $checker, mixed $value): void
 {
 	if ($checker->isString($value)) {
-		echo 'impossible';
+		echo 'confirmed string';
 	}
 }

How to ignore this error #

You can use the identifier method.impossibleType to ignore this error using a comment:

// @phpstan-ignore method.impossibleType
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: method.impossibleType

Rules that report this error #

  • PHPStan\Rules\Comparison\ImpossibleCheckTypeMethodCallRule [1]
Theme
A
© 2026 PHPStan s.r.o.