PhpStorm 2021.3 Help

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.

See noreturn type (php.net) for details.

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

  1. Position the caret at the highlighted line and press Alt+Enter or click the Intention action icon.

  2. Click the arrow next to the inspection you want to suppress and select the necessary suppress action.

Last modified: 17 December 2021