Code Inspection: 'never'-typed function returns a value
Reports the functions with the never
return type hint that may return some value. Functions with such a return type are not expected to return any value and must prevent the rest of the script execution by either calling die()
, exit()
, and so on, or throwing an exception.
In the following example, the function exampleFunction
does not terminate the script execution in any way, which will result in a PHP TypeError
:
function exampleFunction(string $message): never {
echo $message;
}
In the following example, the function exampleFunction
explicitly returns a value, which will result in a PHP Fatal error
:
function exampleFunction(int $value): never {
return $value;
}
Suppress an inspection in the editor
Position the caret at the highlighted line and press Alt+Enter or click
.
Click the arrow next to the inspection you want to suppress and select the necessary suppress action.
Last modified: 11 February 2022