Re: [RFC] Spread Operator in Array Expression

From: Date: Thu, 22 Nov 2018 05:46:42 +0000
Subject: Re: [RFC] Spread Operator in Array Expression
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-103477@lists.php.net to get a copy of this message
On Wed, Nov 21, 2018 at 12:31 PM Nikita Popov <nikita.ppv@gmail.com> wrote: > > On Mon, Nov 19, 2018 at 9:26 AM CHU Zhaowei <me@jhdxr.com> wrote: > > > Hi internals, > > > > I'd like to start the discussion for [RFC: Spread Operator in Array > > Expression](https://wiki.php.net/rfc/spread_operator_for_array). In > > short, this is a syntax similar to argument unpacking, but for array. > > > > You can find the implementation [here]( > > https://github.com/php/php-src/pull/3640). It's still > > WIP, but I'll > > finish it in the next following weeks. > > > This looks reasonable to me. The array_merge() behavior is certainly the > one I would (in PHP) expect intuitively, and it is likely the most useful > one as well, striking a balance between behavior useful for pure vectors > and pure dictionaries (and falling short if it's not either ... as is usual > in PHP). > > Nikita I think we have + and array_merge already. What we *don't* have is something that concatenates solely with values and ignores keys, at least not in a single step. I think ... can be that operator, precisely because this is what it does for function calls as well. In other words, this results in a completely sequentially ordered array, regardless of the key structure of $rest, and does not overwrite positions 0 and 1: $data = [$first, $second, ...$rest]; Those are the semantics that I would like. I think + and array_merge serve the other cases, so no need to deviate from how this works with function calls, which are obviously positional and will not overwrite previous values.

« previous php.internals (#103477) next »