PHP RFC

This is the fourth RFC accepted for PHP 8.1, related to array unpacking with string keys. Previously if you unpacked an array with ...$array a fatal error would occur when one of the arrays keys was a string and not an integer. This RFC lifts this restriction and allows array unpacking with string keys pretty much how you would expect it to work, tying together nicely with named arguments.

Voting result for this RFC was 50 Yes and 0 No. PHP 7.4 added support for unpacking inside arrays through the spread_operator_for_array. At the time, unpacking of string keys was prohibited, both due to uncertainty regarding the semantics, and because the same limitation existed for argument unpacking at the time. In the meantime, the argument unpacking limitation has been removed by the introduction of named arguments.

More PHP RFCs coming

In the next days some more RFCs will finish voting: Include Enumerations in PHP, var_representation() : readable alternative to var_export(), and PHP\iterable\any() and all() on iterables.

There have been three other RFCs already accepted with smaller changes including : Deprecate passing null to non-nullable arguments of internal functions, Restrict $GLOBALS usage and Explicit octal integer notation.

If you want to keep an eye on PHP RFC voting progress have a look at PHP RFC Watch.

Read more details about Array unpacking with string keys at https://wiki.php.net/rfc/array_unpacking_string_keys

LEAVE A REPLY

Please enter your comment!
Please enter your name here