Необязательный именованный аргумент после вариативного аргументаPhp

Кемеровские программисты php общаются здесь
Anonymous
Необязательный именованный аргумент после вариативного аргумента

Сообщение Anonymous »


In PHP 7.x, I had some function that get array of parameters and then some flags.

a simplified sample:

Now in PHP 8.1, I want to change function definition to variadic (unpack array), and function call to named arguments

so I changed the function definition to this:

function sum(...$param, $min=0, $max=100) and function call to this:

echo sum(100, 10, 4, max:50); But I got this error message:

Fatal error: Only the last parameter can be variadic in test.php on line 2

Any idea to solve?

TIA


Источник: https://stackoverflow.com/questions/744 ... c-argument

Вернуться в «Php»