Req #79288 [Opn->Sus]: Allow string key array unpacking inside arrays with array_merge semantics
| From: | requinix@php.net | Date: | Wed, 19 Feb 2020 23:02:14 +0000 |
| Subject: | Req #79288 [Opn->Sus]: Allow string key array unpacking inside arrays with array_merge semantics | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-225636@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79288&edit=1
ID: 79288
Updated by: requinix@php.net
Reported by: caelan89 at gmail dot com
Summary: Allow string key array unpacking inside arrays with
array_merge semantics
-Status: Open
+Status: Suspended
Type: Feature/Change Request
-Package: PHP Language Specification
+Package: Arrays related
Operating System: n/a
PHP Version: 7.4.2
Block user comment: N
Private report: N
New Comment:
I was not polite either. My IRL bad mood leaked onto the internet.
I believe not unpacking keys with function arguments was because of the potential - no, guaranteed -
confusion with associative arrays. Without a named arguments feature, PHP can only really do one
thing: unpack the array in the order the entries were inserted. The order you'd get with a
foreach. That runs directly contrary to how associative arrays (aka hashes or dictionaries) are
typically used in programming: where the order doesn't matter in the slightest. Unpacking an
associative array into function arguments just does not make sense right now.
But that doesn't apply to unpacking arrays *into arrays*. However, what could be a problem is
the potential for one unpacked array to overwrite the keys of a previous unpacked array.
Regardless of all of the above, this sort of change needs some discussion in a place that's
better suited than this bug tracker, ie. the mailing list. Possibly an RFC, depending how it goes.
Previous Comments:
------------------------------------------------------------------------
[2020-02-19 21:48:22] caelan89 at gmail dot com
Description:
------------
A wise person by the handle of "nikic" once said to me: "Pro tip: Don't be a
total dick in your bug reports, and you might get a more information reply next time."
He is totally right. Don't be me. Don't go barging in with such an arrogant and demeaning
tone. It does a disservice to all parties involved.
See: https://bugs.php.net/bug.php?id=79285&edit=2
Please, if you would accept my apology, I am eager to discuss this feature:
---
You've added array unpacking inside of arrays. However, I feel that it could benefit from an
additional feature.
You do not allow this:
$a1 = [
'test' => 1
];
$a2 = [
'test-2' => 2
];
$a3 = [
...$a1,
...$a2
];
From my understanding, it would be semantically equivalent to:
$a3 = array_merge($a1, $a2);
Test script:
---------------
$a1 = [
'test' => 1
];
$a2 = [
'test-2' => 2
];
$a3 = [
...$a1,
...$a2
];
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79288&edit=1