Unpack Array With String Keys¶
In PHP 7.4, the ellipsis operator was introduced to unpack arrays. Initially, it only supported integer keys, and not string keys. This was introduced in PHP 8.0.
PHP code¶
<?php
$array = ['a' => 1];
foo(...$array);
function foo($a) {
echo $a;
}
?>
Before¶
PHP Fatal error: Uncaught Error: Cannot unpack array with string keys
Fatal error: Uncaught Error: Cannot unpack array with string keys
After¶
1
PHP version change¶
This behavior changed in 8.0