Am 29.01.2025 um 21:16 schrieb Rob Landers <rob@bottled.codes>:
> On Wed, Jan 29, 2025, at 20:50, Tim Düsterhus wrote:
>> The `(void)` cast makes the intent of not being interested in the return 
>> value clear. In C casting to `(void)` is an established pattern of 
>> "using" a value that the compiler would otherwise consider unused. 
> 
> I understand what you are saying, but I can also just remove the warning via:
> 
> $_ = outer();
> 
> Which, to me, is clearer on the intent than (void)outer(); It also happens to 
> make the diffs more natural looking when and if the return value gets used 
> during a code review. I'll also note that having (void) doesn't preclude me 
> from using $_ either.

I think the (void) cast is familiar for people from C or the like, the only 
caveat is that it is not backward compatible, i.e. code using it won't work on 
older versions of PHP so migrating to it is not seamless, so it probably should 
not be used for a while in public libraries / packages.

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?

Regards,
- Chris

Reply via email to