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

Named Parameters And Variadic

It is possible to use the three dots ... operator and named parameters when calling a method. The unpacked array must have named arguments, and so does the arguments after it.

In PHP 8.0, it was not possible.

PHP code

<?php

function foo($a, ...$b) {
    echo $a.' '.implode(', ', $b);
}

foo(...[b => 1], a: 2);

?>

Before

PHP Fatal error:  Cannot combine named arguments and argument unpacking 

Fatal error: Cannot combine named arguments and argument unpacking 

After

2 1

PHP version change

This behavior changed in 8.1.

Error Messages

© 2023-2026, Damien Seguy - Exakat