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

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

Am 2025-01-29 21:16, schrieb Rob Landers:
I understand what you are saying, but I can also just remove the warning via: $_ = outer;
Please note that $_ is a regular variable and thus will increase the lifetimes of returned objects (and arrays that can contain objects), which might or might not be observable when implementing __destruct(). Also note that OPcache will actually optimize away dead stores if it can guarantee that the difference is not observable (i.e. if it knows that the function never returns an object and if get_defined_vars() is not called). Of course it would be possible to exclude $_ from this dead-store optimization with PHP 8.5+ to allow for a smoother migration for libraries that require cross-version compatibility. We nevertheless wanted to offer an alternative that might be less confusing than a “special variable” that might also conflict with diagnostics like unused variable detection.
[…] It also happens to make the diffs more natural looking when and if the return value gets used during a code review. […]
Can you clarify what you mean by “more natural looking”? Best regards Tim Düsterhus

Thread (48 messages)

« previous php.internals (#126240) next »