A never returning %s does not return a value, but #[\NoDiscard] requires a return value
Description
This definition include contradicting information: the return type never means that the function will never return, so there should be no return value to handle. On the other hand, the NoDiscard attribute request the caller to do something with the returned values. This is irreconcilable.
Example
<?php
#[\NoDiscard]
function test(): never {
throw new \Exception('Error!');
}
test();
?>
Literal Examples
- A never returning function does not return a value, but #[\NoDiscard] requires a return value
- A never returning method does not return a value, but #[\NoDiscard] requires a return value
Alternatives
- Remove the
neverreturn type. - Remove the
NoDiscardattribute.
Related error messages
- a-void-%s-does-not-return-a-value
- method-%s::%s-cannot-be-#[–nodiscard]
- method-%s::%s-cannot-be-#[–nodiscard]-error_type
Changed Behavior
This error may appear following an evolution in behavior, in previous versions. See