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.
TL;DR: this RFC is not making something impossible to become possible, it's making something not so easy to become easy and efficient.
From: Rowan Collins [email protected]
Sent: Friday, April 5, 2019 12:40 AM
To: Derick Rethans [email protected]
Cc: CHU Zhaowei [email protected]; PHP internals [email protected]
Subject: Re: [PHP-DEV] [RFC] Spread Operator in Array Expression v0.2
Could you add to the RFC what the exact pain point is that this is
trying to address? It looks a little like this is just adding syntax
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
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:
// 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.