Hi Michael > I would like to open a discussion for > https://github.com/php/php-src/issues/10791 . > [https://opengraph.githubassets.com/a23cb565cc8acac6a33ecab5d9ee68a46f046a1ffe215501673156e506695430/php/php-src/issues/10791]<https://github.com/php/php-src/issues/10791> > Array spread append · Issue #10791 · > php/php-src<https://github.com/php/php-src/issues/10791> > Description Currently spread operator can be used for almost anything. But > not for array append. I propose the following to be supported: <?php $arr = > [1, 2]; $arr2 = [3, 4]; $arr[...] = $arr2; // ... > github.com > Appending N elements to an array is quite common language usage pattern and I > belive it should be supported natively for shorter syntax, language > consistency and performance.Hi Michael
There are a few questions that come to mind (there may be more). * Are integer keys preserved? I'm assuming no, as otherwise it would be the same as `$a + $b`. * What is the return value of the expression `$a[...] = $b`? I'm assuming $a after the additions of $b? * How does it behave in combination with `ArrayAccess`? Throw? Call `offsetSet` for each element? * How does it interact with references? E.g. This is valid PHP code: `assign_by_ref($a[])` (https://3v4l.org/qoJYn) * How does it interact with undefined/null values? E.g. `$a[] = 42;` works without declaring $a first. * Is there a need for this? Given that `+` doesn't work with sequential lists and `array_push($a, ...$b)` doesn't work with strings I'd say possibly. `[...$a, ...$b]` works but requires duplication of the array which in loops can be detrimental to performance. Ilija -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php