Menu

← Back to assert.*

Error Identifier: assert.impossibleType

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

/**
 * @phpstan-assert string $i
 */
function assertString(int $i): void
{
}

Why is it reported? #

The @phpstan-assert PHPDoc tag declares an assertion that can never be satisfied given the parameter’s type. The asserted type and the parameter type are completely incompatible, so the assertion would always fail.

In the example above, the parameter $i has a native type of int, and the @phpstan-assert tag asserts it is string. Since int and string are disjoint types, this assertion can never succeed.

How to fix it #

Widen the parameter type so the assertion can meaningfully narrow it:

 <?php declare(strict_types = 1);
 
 /**
  * @phpstan-assert string $i
  */
-function assertString(int $i): void
+function assertString(mixed $i): void
 {
 }

Or change the asserted type to one compatible with the parameter:

 <?php declare(strict_types = 1);
 
 /**
- * @phpstan-assert string $i
+ * @phpstan-assert positive-int $i
  */
-function assertString(int $i): void
+function assertPositiveInt(int $i): void
 {
 }

How to ignore this error #

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

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

Rules that report this error #

  • PHPStan\Rules\PhpDoc\FunctionAssertRule [1]
  • PHPStan\Rules\PhpDoc\MethodAssertRule [1]

Edit this page on GitHub

Theme
A
© 2026 PHPStan s.r.o.