Re: RFC: Marking return values as important (#[\NoDiscard])

From: Date: Thu, 30 Jan 2025 15:50:59 +0000
Subject: Re: RFC: Marking return values as important (#[\NoDiscard])
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to [email protected] to get a copy of this message
Hi

Am 2025-01-29 23:48, schrieb Christian Schneider:
I guess another option would be to define a function nop($_) {} and then use nop(outer()); but my question is whether $_ = outer() and nop(outer()) will be guaranteed to not being optimized in a way which causes the warning to reappear. I don't know much about the optimizations being done but this could be an issue in the future, no?
For $_ see my reply to Rob. For the function: OPcache will attempt to inline functions that only return a (implicit) return statement. However this only works if the function is defined in the same file, as OPcache currently cannot perform cross-file optimizations. I'd say that defining the nop() function in a dedicated file is currently the most reliable solution to prevent OPcache from optimizing away the usage in a backwards-compatible way. Of course the best solution is actually doing something useful with the return value, as the attribute is intended to point out when not using the return value is very likely to be wrong. We would expect it to be rarely necessary to just suppress the warning. Best regards Tim Düsterhus

Thread (48 messages)

« previous php.internals (#126241) next »