Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105096 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 56709 invoked from network); 5 Apr 2019 11:35:11 -0000 Received: from unknown (HELO poczta.brzuchalski.com) (188.165.245.118) by pb1.pair.com with SMTP; 5 Apr 2019 11:35:11 -0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by poczta.brzuchalski.com (Postfix) with ESMTP id 1CC79298423E for ; Fri, 5 Apr 2019 10:30:57 +0200 (CEST) Received: from poczta.brzuchalski.com ([127.0.0.1]) by localhost (poczta.brzuchalski.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id vCmPQjlmlAnQ for ; Fri, 5 Apr 2019 10:30:53 +0200 (CEST) Received: from mail-lj1-f178.google.com (unknown [209.85.208.178]) by poczta.brzuchalski.com (Postfix) with ESMTPSA id 23D072984236 for ; Fri, 5 Apr 2019 10:30:53 +0200 (CEST) Received: by mail-lj1-f178.google.com with SMTP id j89so4518242ljb.1 for ; Fri, 05 Apr 2019 01:30:53 -0700 (PDT) X-Gm-Message-State: APjAAAVbs9aeDy2oF++hnGPYKVHtGP3xmtXnZ72omtDx9tAM2/031gq/ 0TueAXzOvBd70U55BmscXKcOxVcXBa6/zUnyVRg= X-Google-Smtp-Source: APXvYqxtuiuee4QUK9cMWVA3+DSIILmlb4+r5cfNOsgkY8MkKO2WsOyKfrKVWYo4eU/zCeeeuW6wCrtHof1r35vQlhQ= X-Received: by 2002:a2e:b058:: with SMTP id d24mr6277354ljl.42.1554453052581; Fri, 05 Apr 2019 01:30:52 -0700 (PDT) MIME-Version: 1.0 References: <003a01d4eaf0$c17d6c20$44784460$@jhdxr.com> <00a401d4eb7c$afa671e0$0ef355a0$@jhdxr.com> In-Reply-To: <00a401d4eb7c$afa671e0$0ef355a0$@jhdxr.com> Date: Fri, 5 Apr 2019 10:30:38 +0200 X-Gmail-Original-Message-ID: Message-ID: To: CHU Zhaowei Cc: Rowan Collins , Derick Rethans , PHP internals Content-Type: multipart/alternative; boundary="00000000000004ef5f0585c44e05" Subject: Re: [PHP-DEV] [RFC] Spread Operator in Array Expression v0.2 From: michal@brzuchalski.com (=?UTF-8?Q?Micha=C5=82_Brzuchalski?=) --00000000000004ef5f0585c44e05 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable pt., 5 kwi 2019 o 08:56 CHU Zhaowei napisa=C5=82(a): > Here is a MDN document for spread operator in JS: > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operato= rs/Spread_syntax#Spread_in_array_literals > and hope you find more useful examples. > The next paragraph in MDN document is spread operator for object literals https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators= /Spread_syntax#Spread_in_object_literals Now JavaScript objects can be used like our array with keys and I simply don't understand why we cannot preserve keys, like in JS object literals Sample code: JavaScript: var a =3D {foo: true, ...{bar: "baz"}}; // become {foo: true, bar: "baz"} and you can access it via a.foo or as an array dimension a['foo'] - more or less like PHP arrays, right with key as a dimenrsion in array Your RFC covers: PHP: $a =3D [1, 2, 3, ...[4, 5, 6]]; // resulting [1, 2, 3, 4, 5, 6] What would happen in: a) PHP: $a =3D ['foo' =3D> true, ...[4, 5, 6]]; // ?? b) PHP $a =3D ['foo' =3D> true, ...['bar' =3D> 'baz']] // error ?? Don't get me wrong I just see spread operator in function arguments a different feature which allows working with variadic parameters, and we're talking about the different feature here which only use the same operator, right? --00000000000004ef5f0585c44e05--