MIR1514
NoDiscardReturnIgnored
A function or method marked #[\NoDiscard] is called as a statement on its own, so its return
value is thrown away. From PHP 8.5 this emits a warning. Builtins such as
DateTimeImmutable::add() carry the attribute because calling them only for their side effects
is a bug.
Example
Section titled “Example”<?phpfunction shift(DateTimeImmutable $date): DateTimeImmutable { $date->add(new DateInterval('P1D')); // returns a new object; $date is unchanged return $date;}How to fix
Section titled “How to fix”Use the return value, or cast the call to (void) when discarding it is intended:
<?phpfunction shift(DateTimeImmutable $date): DateTimeImmutable { return $date->add(new DateInterval('P1D'));}