Req #79285 [Opn->Nab]: Allow unpacking of arrays with string keys into other arrays

From: Date: Wed, 19 Feb 2020 18:57:15 +0000
Subject: Req #79285 [Opn->Nab]: Allow unpacking of arrays with string keys into other arrays
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-225629@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 Updated by: requinix@php.net Reported by: caelan89 at gmail dot com Summary: Allow unpacking of arrays with string keys into other arrays -Status: Open +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: 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. Previous Comments: ------------------------------------------------------------------------ [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

« previous php.bugs (#225629) next »