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

Reply via email to