phpinspectionsea
phpinspectionsea copied to clipboard
Unused function result inspection warning on methods/ functions with never return type (false positive)
Subject | Details |
---|---|
Plugin | Php Inspections (EA Ultimate), 2021.5 |
Language level | 8.1 |
Current Behavior
<?php
class Example {
final public function errorExit(string|Stringable $message): never
{
exit((string) $message);
}
}
$example = new Example();
$example->errorExit('program failed for x reason');
[EA] Function result is not used - line 10 ( the calling errorExit() line )
Rule: Unused function result Description: Reports cases when function result is not used (can be a dead code fragment, an merging issue or a bug)
Expected Behavior
never is a new return type added in PHP 8.1.
A function/method that is declared with the never return type indicates that it will never return a value, and always throws an exception or terminates with a die/exit call.
never return type is similar to the existing void return type, but the never type guarantees that the program will terminate or throw. In other words, a function/method declared never must not call return at all, not even in the return; form.
Since the method is declared as never there is no result to be unused, ie inspection false positive.