Req #76613 [Opn->Sus]: Argument unpacking: Add support for associative arrays

From: Date: Thu, 12 Jul 2018 02:38:08 +0000
Subject: Req #76613 [Opn->Sus]: Argument unpacking: Add support for associative arrays
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-216282@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=76613&edit=1 ID: 76613 Updated by: requinix@php.net Reported by: nowm at yandex dot ru Summary: Argument unpacking: Add support for associative arrays -Status: Open +Status: Suspended Type: Feature/Change Request Package: Arrays related Operating System: any PHP Version: 5.6.36 Block user comment: N Private report: N New Comment: > In order to ensure forward-compatibility with named arguments the unpacking operator does not > support string keys. That particular RFC is no longer active but the feature as a whole still has its proponents. Previous Comments: ------------------------------------------------------------------------ [2018-07-12 02:09:00] nowm at yandex dot ru Description: ------------ This request is related to any PHP 5.6+ When you pass an associative array for argument unpacking (https://wiki.php.net/rfc/argument_unpacking), you get a fatal error, "Cannot unpack array with string keys". As I see, there are no reasons to limit unpacking to only numeric arrays. For example, it does not use numeric keys for ordering values, so key type has no any sense: <?php $array = [1 => 'b', 2 => 'c', 0 => 'a']; // Outputs "b c a", not "a b c" // It shows that array unpacking does not rely on keys at all var_dump(...$array); Test script: --------------- <?php $array = ['a' => 'one', 'b' => 'two', 'c' => 'three']; var_dump(...$array); Expected result: ---------------- string(3) "one" string(3) "two" string(5) "three" Actual result: -------------- PHP Fatal error: Uncaught Error: Cannot unpack array with string keys in Standard input code:5 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=76613&edit=1

« previous php.bugs (#216282) next »