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 vesrion, a unified message mentioning functions applied to all structures.
Example¶
<?php
class X {
function foo() : never {
return true;
}
}
?>
Solutions¶
Remove the
return
keyword in the body of the method.Change the
never
return type to another type.