mirror of
https://github.com/php/php-src.git
synced 2026-03-24 08:12:21 +01:00
This adds support for:
$array1 = ['a' => 1, 'b' => 2];
$array2 = ['b' => 3, 'c' => 4];
$array = [...$array1, ...$array2];
// => ['a' => 1, 'b' => 3, 'c' => 4]
RFC: https://wiki.php.net/rfc/array_unpacking_string_keys
Closes GH-6584.
19 lines
323 B
PHP
19 lines
323 B
PHP
--TEST--
|
|
Array unpacking does not work with non-integer/string keys
|
|
--FILE--
|
|
<?php
|
|
function gen() {
|
|
yield [] => 1;
|
|
yield 1.23 => 123;
|
|
}
|
|
|
|
try {
|
|
[...gen()];
|
|
} catch (Error $ex) {
|
|
echo "Exception: " . $ex->getMessage() . "\n";
|
|
}
|
|
|
|
?>
|
|
--EXPECT--
|
|
Exception: Keys must be of type int|string during array unpacking
|