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
Solutions¶
Remove the
neverreturn type.Remove the
NoDiscardattribute.
Changed Behavior¶
This error may appear following an evolution in behavior, in previous versions. See ` <https://php-changed-behaviors.readthedocs.io/en/latest/behavior/.html>`_.