Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:78710 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12207 invoked from network); 5 Nov 2014 10:24:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 5 Nov 2014 10:24:56 -0000 Authentication-Results: pb1.pair.com header.from=are.you.winning@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=are.you.winning@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.192.41 as permitted sender) X-PHP-List-Original-Sender: are.you.winning@gmail.com X-Host-Fingerprint: 209.85.192.41 mail-qg0-f41.google.com Received: from [209.85.192.41] ([209.85.192.41:48411] helo=mail-qg0-f41.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id C8/20-10214-5FAF9545 for ; Wed, 05 Nov 2014 05:24:54 -0500 Received: by mail-qg0-f41.google.com with SMTP id q107so12041678qgd.28 for ; Wed, 05 Nov 2014 02:24:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc:content-type; bh=IbMZDBMsyO92toBuSPF8wKrKAq4F8PNqjxM3mgiIaJI=; b=G71q1dW5WbCr8B65zJ4wjr2nukDUmalv+wAYnRFH00/Fr8mRdqzw/oOHT/Iyvqu8Vy vrEbjuAcfw6vgQrY+ZOtdQk/di9Movliq9vtKyNI03ExI/vKbqCqR+1giVj+9KIoxUhN L18Qy71/tQHAi9xnc71NoDs/zqL7CC5UlZ/0GRCIjA+2GCZiXzF0QX9E/IkS5c97u1Ix Xhlj+UusuoT4DgDQIHZIN4TEGN2xBJs0+u7XTNiBwaZXKpr4JaYvib6BTq9N96gNU9r0 Z9BxaFTy5Yom02lZb7KD9mqvz6u0ZWAmZzTgfr3cRfVnPKjjO3ZWZ/f1fqKgNCHnD7OG /Kkw== MIME-Version: 1.0 X-Received: by 10.140.84.177 with SMTP id l46mr80213133qgd.100.1415183068879; Wed, 05 Nov 2014 02:24:28 -0800 (PST) Sender: are.you.winning@gmail.com Received: by 10.140.239.194 with HTTP; Wed, 5 Nov 2014 02:24:28 -0800 (PST) In-Reply-To: References: Date: Wed, 5 Nov 2014 10:24:28 +0000 X-Google-Sender-Auth: uAYfbu6X8_Um--cS4yD97NA1Voo Message-ID: To: Rowan Collins Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary=001a11c14c241ce2b8050719fc22 Subject: Re: [PHP-DEV] [RFC] Additional splat operator usage From: cw@daverandom.com (Chris Wright) --001a11c14c241ce2b8050719fc22 Content-Type: text/plain; charset=UTF-8 On 4 November 2014 18:14, Rowan Collins wrote: > On 3 November 2014 22:45:11 GMT, Chris Wright wrote: > >Good evening list, > > > >I'd like to open discussion a relatively simple and clear-cut RFC, > >either > >people will like it or they won't, there isn't a lot more to say here > >than > >what's in the RFC so please have a read. > > > >https://wiki.php.net/rfc/additional-splat-usage > > I like the concept with list-style arrays, but find the behaviour with > regards associative arrays quite confusing. There's already a difference in > behaviour between array_merge and + in this regard, and having a third way > of writing the same thing isn't great - it would apparently be legal to > write $foobar = [...$foo, ...$bar]; to simply merge two existing arrays. > > It would be legal and I don't see this as a problem? This would be identical to array_merge($foo, $bar) and this is intentional, the proposal is entirely intended to make merging literal constant arrays and variable arrays simpler, it doesn't add yet another set of rules for how the merge will be performed - we really don't need that. If you wanted to discard the keys and turn two associative arrays into a list, you could write $foobar = [...array_values($foo), ...array_values($bar)] (but I don't recommend this). More sensible uses w.r.t. associative array merging might be creating the array to pass to PDOStatement->execute() (this is quite a contrived example, but I have had effectively this use case in more complex code): function execute_statement_with_extra_params(PDOStatement $stmt, array $params) { return $stmt->execute(['param1' => 1, 'param2' => 'value', ...$params]); } I had a similar case recently and was surprised to find that it didn't work (i.e. I find it quite intuitive), which is the main motivation for writing this RFC. > If anything, I think I would expect the keys of splatted arrays to be > discarded, since it seems most natural to use this in a list context, but I > can imagine always having to check in the manual. > > -- > Rowan Collins > [IMSoP] > > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a11c14c241ce2b8050719fc22--