On Tue, Mar 4, 2025, 23:22 Tim Düsterhus <t...@bastelstu.be> wrote: > > > Or identify that the function has the NoDiscard attribute and based on > that > > do not optimize away the variable? > > First things first: It's not a super important optimization to have, the > assignment to a variable is one of the cheaper operations - and given > that OPcache needs to know about the function it's also pretty limited > in application. Of course you can also always just remove the assignment > yourself (or ask your favorite IDE or static analyzer to point it out > for you). > > That said: Checking for the attribute and performing the optimization is > likely possible, though likely of limited cost/benefit. In any case that > would be an implementation detail that does not change observable > behavior. The RFC defines that `(void)` or alternatively `$_` will be > the solution that guarantees that the warning will be suppressed (which > will then also be part of the documentation), how exactly that will work > internally is something that can and will change when refactoring and > evolving the engine and OPcache. > > Thank you for explaining.
My motivation for asking is because I believe that special casing $_ variable might not be a desirable solution, and I personally find it worse than (void) casting. And so, people might vote "No" for the first vote because they are not happy with either results of the second option. And maybe we can find a technical solution that doesn't require a behavior/documentation change if second vote fails. I agree that this optimization is not really important, so finding a way to avoid it would be nice. -- Alex