website/errors/phpstanPlayground.never.md
<?php declare(strict_types = 1);
function bail(): void
{
throw new \RuntimeException('Something went wrong');
}
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.
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');
}