Hi Marc On 3/3/25 17:14, Marc B. wrote:
In this thread, I only found the information that currently OPcache does not discard such unused assignments. It would be good to know if such optimization could be considered to not end up in a situation that such optimization would be useful but can't be applied as of this feature.
Unless it knows for sure that the function is unable to return an object (this includes arrays, which could contain objects), OPcache is already disallowed to elide the dead store. Otherwise this would result in an observable behavioral change, since destructors are called immediately rather than when the variable goes out of scope / is overwritten. For practically all modern code this means that this optimization only affects internal functions, since OPcache only looks at a single file. Thus it does not know about the return type of userland functions defined in a different file.
In fact, if you call `get_defined_vars()` or similar functions the dead store elimination is also disabled, since that would result in an observable behavioral change.
Should the `(void)` cast not be accepted, we will only special case the assignment to `$_` to not be elided, even if OPcache knows that the function will never return an object. The behavior for other variables will remain unchanged.
Best regards Tim Düsterhus