A never-returning method must not return¶
Description¶
When using the never keyword, the method shall not use the return keyword. never means that the method will not return, but rather die, throw an exception, or trigger an error.
Also note that never cannot be used in a union type.
This error message applies to methods, since PHP 8.4. Before that version, a unified message mentioning functions applied to all structures.
Example¶
<?php
class X {
function foo() : never {
return true;
}
}
?>
Solutions¶
Remove the
returnkeyword in the body of the method.Change the
neverreturn type to another type.