A (void) cast disables it:
<?php
$a = new DateTimeImmutable();
*(void)* $a->setDate(2025, 5, 4);
?>
You can't use #[Discard] when:
- • The function is typed with : void or : never
- • For magic methods (including the constructor) that require : void, or have no return type at all
- • For property hooks