Error Identifier: phpstanPlayground.never
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 bail(): void
{
throw new \RuntimeException('Something went wrong');
}
Why is it reported? #
The function or method always throws an exception or terminates script execution (e.g. via exit or die), but its return type is not declared as never. The never return type was introduced in PHP 8.1 and signals that the function will never return normally.
This information helps PHPStan understand that code after a call to this function is unreachable, enabling more precise analysis.
How to fix it #
Change the return type to never:
<?php declare(strict_types = 1);
-function bail(): void
+function bail(): never
{
throw new \RuntimeException('Something went wrong');
}
If you need to support PHP versions before 8.1, use the @return never PHPDoc tag:
<?php declare(strict_types = 1);
+/** @return never */
function bail(): void
{
throw new \RuntimeException('Something went wrong');
}
Non-ignorable error #
This error cannot be ignored using @phpstan-ignore or the ignoreErrors configuration. Non-ignorable errors indicate code that would cause a crash or a fatal error at runtime, or a fundamental problem in the analysed code that must be addressed.