# [RFC] Array unpacking with string keys

- Thread: https://externals.io/message/112791
- Original archive: https://news-web.php.net/php.internals/112791
- Started by Nikita Popov on 2021-01-07T11:30:48+00:00
- Messages: 5
- RFC: Array unpacking with string keys (Implemented (PHP 8.1)) — https://externals.io/rfc/array_unpacking_string_keys.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #112791 — Nikita Popov — 2021-01-07T11:30:48+00:00

URL: https://externals.io/message/112791#112791

Hi internals,

I'd like to propose that string keys be allowed when unpacking into arrays:
https://wiki.php.net/rfc/array_unpacking_string_keys

Especially as unpacking in calls supports string keys now, I believe it is
time to drop this limitation for arrays as well.

Regards,
Nikita

---

## #112805 — Larry Garfield — 2021-01-07T19:18:46+00:00

URL: https://externals.io/message/112791#112805 · In reply to: #112791

> Hi internals,
> 
> I'd like to propose that string keys be allowed when unpacking into arrays:
> https://wiki.php.net/rfc/array_unpacking_string_keys
> 
> Especially as unpacking in calls supports string keys now, I believe it is
> time to drop this limitation for arrays as well.
> 
> Regards,
> Nikita

Hard yes.  I ran into a case just yesterday (while doing some sample code for immutability) when I wanted to merge associative arrays this way and the alternate was much yuckier.

--Larry Garfield

---

## #112806 — Kalle Sommer Nielsen — 2021-01-07T21:07:10+00:00

URL: https://externals.io/message/112791#112806 · In reply to: #112805

Den tor. 7. jan. 2021 kl. 21.19 skrev Larry Garfield <larry@garfieldtech.com>:
> Hard yes.  I ran into a case just yesterday (while doing some sample code for immutability) when I wanted to merge associative arrays this way and the alternate was much yuckier.

Seconded, I ran into a similar thing yesterday and it took me a bit to
figure out what was going on. This RFC would fix that behavior so big
+1

-- 
regards,

Kalle Sommer Nielsen
kalle@php.net

---

## #112809 — tyson andre — 2021-01-08T02:59:53+00:00

URL: https://externals.io/message/112791#112809 · In reply to: #112791

Hi Nikita,

> I'd like to propose that string keys be allowed when unpacking into arrays:
> https://wiki.php.net/rfc/array_unpacking_string_keys
>
> Especially as unpacking in calls supports string keys now, I believe it is
> time to drop this limitation for arrays as well.

+1, was considering proposing the same array_merge semantics as this RFC
but didn't get around to looking into why this wasn't in the original php 7.4 array unpacking RFC.

Regards,
Tyson

---

## #112935 — Nikita Popov — 2021-01-20T08:55:39+00:00

URL: https://externals.io/message/112791#112935 · In reply to: #112791

> Hi internals,
>
> I'd like to propose that string keys be allowed when unpacking into
> arrays: https://wiki.php.net/rfc/array_unpacking_string_keys
>
> Especially as unpacking in calls supports string keys now, I believe it is
> time to drop this limitation for arrays as well.
>
> Regards,
> Nikita
>

This RFC seems to have been well-received, so I plan to start voting soon.

Nikita
