Re: A little syntactic sugar on array_* function calls?

From: Date: Mon, 31 May 2021 10:02:21 +0000
Subject: Re: A little syntactic sugar on array_* function calls?
References: 1 2 3 4 5 6 7 8 9 10 11 12 13  Groups: php.internals 
Request: Send a blank email to internals+get-114675@lists.php.net to get a copy of this message
On Fri, May 28, 2021 at 9:00 PM Mark Randall <marandall@php.net> wrote:

> On 28/05/2021 15:31, Nikita Popov wrote:
> > This is a more complex case. In this case the compiler doesn't know in
> > advance whether the argument is passed by value or by reference. What
> > happens here is:
>
>
> I'm trying to wrap my head around this, but if a function arg can handle
> this, does something internal to the engine preclude fetching in write
> context, after already fetching in read context, other than performance?
>
> So can the initial fetch be performed with FETCH_DIM_R, handling the
> object case + any other scalars, and if and only if the value is an
> array and operating on what would traditionally be a by-ref, repeating
> the previous lookup with FETCH_DIM_W?
>

This is theoretically possible, in that this is exactly how $a[$b][$c] ??=
$d is implemented. Everything is first fetched as FETCH_DIM_IS and then
again as FETCH_DIM_W if an assignment is necessary. However, this does
require emitting both fetch sequences, with one guarded by a branch,
together with temporary copies to allow re-fetching without re-evaluating
side-effecting operands. Of course, it also has fun interactions with magic
ArrayAccess/__get, in which case both fetches may produce different
results. All this is something we can live with for the ??= operator, but
not for every single method call.

Regards,
Nikita


Thread (29 messages)

« previous php.internals (#114675) next »