On Wed, 12 Feb 2025, Volker Dusch wrote: > On Wed, Jan 29, 2025 at 4:12 PM Tim Düsterhus <t...@bastelstu.be> wrote: > > > Volker and I would like to start discussion on our RFC to allow "Marking > > return values as important (#[\NoDiscard])". > > > > Please find the following resources for your reference: > > > > - RFC: https://wiki.php.net/rfc/marking_return_value_as_important > > - Implementation: https://github.com/php/php-src/pull/17599 > Hello everyone, > > it's been two weeks, but given the feedback we received, we don't feel > the discussion didn't reach a conclusive resolution yet. > > So we wanted to solicit additional opinions. In an attempt to > summarize the discussion, how we see it, there are two main points of > contention we'd like to discuss further. > > a) Intentionally discarding the return value > > The `(void)flock($fp);` syntax was the main thing discussed on the list. > With `$_ = flock($fp);` as the most suggested alternative. > > The issue with using `$_` as it currently stands, is that the unused > variable would be cleaned up by OPcache. Should we instead have a > special case in OPcache ensuring it does not apply its optimization to > a variable if it's named `$_` instead? The semantic difference would > be that $_ would keep returned values (and objects) alive and in > memory, whereas (void) would discard them immediately. Leading to > different times when, for example, destructors would be called. > > The consequence of this would be that 3rd party tools like IDEs and > Static and Dynamic Code Analyzers would also have to build that > special case in to not produce "unused variable" warnings. > > We're also happy to change the secondary vote to "(void) vs $_" as we > feel there needs to be a way to discard the return value consistently > for this to be a complete and usable feature.
I would not be in favour of special casing this, and henceforth the (void) cast makes more sense to me. Mostly, because the special casing has to be done in many places, and in many tools. > b) Naming of the attribute > > Nobody mentioned this on the list, but before opening a vote we'd like > to heard if the attribute name makes sense to you. > > We've chosen #[NoDiscard] as it's also used in C and C++. See [1] for > the full list of references. If you feel this doesn't fit with PHP, we > welcome other suggestions. I think it fits, and there is already precedence. cheers, Derick -- https://derickrethans.nl | https://xdebug.org | https://dram.io Author of Xdebug. Like it? Consider supporting me: https://xdebug.org/support mastodon: @derickr@phpc.social @xdebug@phpc.social