Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Unpack Array With String Keys

The ellipsis operator was introduced to unpack arrays. In PHP 7.4, 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.

Error Messages

Extension

Analyzer

© 2023-2026, Damien Seguy - Exakat