Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105089 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 27011 invoked from network); 5 Apr 2019 10:00:45 -0000 Received: from unknown (HELO smtpbgsg2.qq.com) (54.254.200.128) by pb1.pair.com with SMTP; 5 Apr 2019 10:00:45 -0000 X-QQ-mid:Yeas17t1554447388t129t06582 Received: from 90373548D78A4F9A84016F99F658592A (me@jhdxr.com [155.69.203.163]) X-QQ-SSF:00000000000000F0F61000000000000 To: "'Rowan Collins'" , "'Derick Rethans'" Cc: "'PHP internals'" References: <003a01d4eaf0$c17d6c20$44784460$@jhdxr.com> In-Reply-To: Date: Fri, 5 Apr 2019 14:56:24 +0800 Message-ID: <00a401d4eb7c$afa671e0$0ef355a0$@jhdxr.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Content-Language: en-us Thread-Index: AQIKWL9sdr8zqvFBmN46rJnDR+4gNwHdTn8dAempWaalpAQJIA== X-QQ-SENDSIZE: 520 Feedback-ID: Yeas:jhdxr.com:qybgforeign:qybgforeign1 X-QQ-Bgrelay: 1 Subject: RE: [PHP-DEV] [RFC] Spread Operator in Array Expression v0.2 From: me@jhdxr.com (=?utf-8?b?Q0hVIFpoYW93ZWk=?=) Thanks Rowan. IMO it's very natural to try to apply operators to similar = scenario, array construction in this case, and I'm completing the = missing piece of jigsaw puzzle. 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. TL;DR: this RFC is not making something impossible to become possible, = it's making something not so easy to become easy and efficient. -----Original Message----- From: Rowan Collins =20 Sent: Friday, April 5, 2019 12:40 AM To: Derick Rethans Cc: CHU Zhaowei ; PHP internals Subject: Re: [PHP-DEV] [RFC] Spread Operator in Array Expression v0.2 On Thu, 4 Apr 2019 at 17:14, Derick Rethans wrote: > Could you add to the RFC what the exact pain point is that this is=20 > trying to address? It looks a little like this is just adding syntax=20 > for the sake of it. > Not everything is about pain, some things are just about gain. ;) The link Levi shared about Dart included some interesting examples of = where spreads are useful, some of which you can probably imagine = happening in PHP: https://medium.com/dartlang/making-dart-a-better-language-for-ui-f1ccaf9f= 546c It also takes us a step closer to having a short-hand for = iterator_to_array, in the shape of [...$iterator]. On its own, that's = still pretty ugly, but it's not hard to come up with cases where it = would be a lot nicer, like concatenating two iterators: // Before array_merge(iterator_to_array($iter1), iterator_to_array($iter2)) // Or to generalise to all iterables array_merge( is_array($iter1) ? $iter1 : iterator_to_array($iter1), is_array($iter2) ? $iter2 : iterator_to_array($iter2) ) // After (handles both cases) [ ...$iter1, ...$iter2 ] Granted, I can't point to a real-life example of that, but it shows that = this isn't just new syntax for something that's already easy. Regards, -- Rowan Collins [IMSoP]