Req #79285 [Com]: Allow unpacking of arrays with string keys into other arrays
| From: | caelan89 at gmail dot com | Date: | Wed, 19 Feb 2020 20:53:54 +0000 |
| Subject: | Req #79285 [Com]: Allow unpacking of arrays with string keys into other arrays | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225631@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79285&edit=1
ID: 79285
Comment by: caelan89 at gmail dot com
Reported by: caelan89 at gmail dot com
Summary: Allow unpacking of arrays with string keys into
other arrays
Status: Not a bug
Type: Feature/Change Request
Package: Scripting Engine problem
Operating System: n/a
PHP Version: 7.4.2
Block user comment: N
Private report: N
New Comment:
requinx,
Unpacking an array to pass arguments to a function dynamically is not the same thing as unpacking an
array inside an array to merge in-place.
Previous Comments:
------------------------------------------------------------------------
[2020-02-19 18:57:15] requinix@php.net
https://wiki.php.net/rfc/spread_operator_for_array#string_keys
> In order to make the behavior consistent with argument unpacking, string keys are not
> supported.
------------------------------------------------------------------------
[2020-02-19 15:13:25] caelan89 at gmail dot com
Description:
------------
You've added in array unpacking inside of arrays.
However, it is a half-baked solution (if you can even call it that), and relatively useless except
for a few use cases.
You do not allow this:
$a1 = [
'test' => 1
];
$a2 = [
'test-2' => 2
];
$a3 = [
...$a1,
...$a2
];
There is absolutely zero reason, other than your inconvenience building it, as to why this should be
forbidden. None at all.
It is semantically equivalent to:
$a3 = array_merge($a1, $a2);
Why on earth should I not be able to do the same with with the much neater and preferable array
unpacking syntax?
Test script:
---------------
$a1 = [
'test' => 1
];
$a2 = [
'test-2' => 2
];
$a3 = [
...$a1,
...$a2
];
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79285&edit=1