On Sun, Jul 25, 2021 at 4:35 PM David Rodrigues <david.pro...@gmail.com> wrote: > Anyway, I don't know if this is actually possible, or if the cost-benefit > would be better than what there is today. But I believe it is a path to be > thought of. >
Sadly, no. The function doesn't know where the variable is going to be stored to, so it can't know if the one reference it's receiving is about to be overwritten. Technically, the information is in the op_array, but exposing that to an implementation handler is... dangerous and sets a bad precedent. A much more direct and maintainable solution would be to introduce a new function that intentionally modifies by reference. This doesn't give us a free fix for existing code, but it does provide a path for new code to be more efficient. So then you have to ask, should we kitchen sink something in for this? Maybe, the perf argument is compelling. I'd also argue that this request reinforces calls for type methods. $arr->push($otherArr); would be a stronger candidate, for example. In fact, I think the DS extension might actually have what you're looking for already. TL;DR - Maybe look at https://www.php.net/manual/en/ds-map.putall.php ? -Sara