The return value of method %s::%s() should either be used or intentionally ignored by casting it as (void)%S¶
Description¶
When a method has the NoDiscard attribute, it means that its returned value must be collected and used. When the value is simply ignored, PHP stops execution with a fatal error.
Example¶
<?php
#[\NoDiscard]
function foo() {
return 1;
}
foo();
?>
Solutions¶
Store the returned value in a variable, and use it to check the returned value.
Use the function call as an argument of another method.
Use the
(void)cast, to explicitly ignore the result.
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>`_.