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

Internal function %s%s%s() does not accept named variadic arguments

Description

Internal (C-implemented) functions with a variadic parameter, such as array_merge()’s ...$arrays, only ever have a single name for that parameter. When a call spreads an array with string keys into such a function using ..., PHP tries to match each key against a parameter name, and every key besides the one matching the variadic parameter’s own name is rejected, since there is no other named slot for it to bind to.

This restriction is specific to internal functions: user-defined variadic functions accept arbitrary named arguments into their variadic parameter without complaint.

Example

<?php

$parts = ['x' => [1], 'y' => [2]];

array_merge(...$parts);

?>

Literal Examples

  • Internal function array_merge() does not accept named variadic arguments

Alternatives

  • Apply array_values() to the array before spreading it into the internal function, so its keys are reset to plain integers and no longer interpreted as parameter names.

In previous PHP versions, this error message used to be :ref:array_merge()-does-not-accept-unknown-named-parameters.

Changed Behavior

This error may appear following an evolution in behavior, in previous versions. See [Prior to PHP 8.6, the same ArgumentCountError was thrown, but worded “%s%s%s() does not accept unknown named parameters” (e.g. “array_merge() does not accept unknown named parameters”), without the “Internal function” prefix and without naming variadic arguments specifically as the cause.](Prior to PHP 8.6, the same ArgumentCountError was thrown, but worded “%s%s%s() does not accept unknown named parameters” (e.g. “array_merge() does not accept unknown named parameters”), without the “Internal function” prefix and without naming variadic arguments specifically as the cause.)