Req #76613 [NEW]: Argument unpacking: Add support for associative arrays
| From: | nowm at yandex dot ru | Date: | Thu, 12 Jul 2018 02:09:02 +0000 |
| Subject: | Req #76613 [NEW]: Argument unpacking: Add support for associative arrays | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-216281@lists.php.net to get a copy of this message | ||
From: nowm at yandex dot ru
Operating system: any
PHP version: 5.6.36
Package: Arrays related
Bug Type: Feature/Change Request
Bug description:Argument unpacking: Add support for associative arrays
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 bug report at https://bugs.php.net/bug.php?id=76613&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=76613&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=76613&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=76613&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=76613&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=76613&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=76613&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=76613&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=76613&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=76613&r=support
Expected behavior: https://bugs.php.net/fix.php?id=76613&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=76613&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=76613&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=76613&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=76613&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=76613&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=76613&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=76613&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=76613&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=76613&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=76613&r=mysqlcfg