I might be off here, but I believe the issue with that is that it's a
performance problem. You would have to check each key and function
parameter for a match, which would be slow.
You can, however, achieve what you're after just by using an array without
any packing/unpacking.
function foo(Array $args) {
// Expected arguments
$default = ["name" => null, "birthday" => null];
// Get actual arguments
$input = array_intersect_key($args, $default) + $default; // final
if (!isset($input['name'])) {
// ohnoes you forgot your name
}
if (!isset($input['birthday'])) {
// ohnoes you forgot your birthday
}
// otherwise use $Input['name'] and $input['birthday'] here...
}
On Sat, Mar 14, 2020 at 10:43 AM Midori Koçak <[email protected]> wrote:
> Dear Internals,
>
> I would like to as you a question. I know that it is possible to use an
> array to function parameters like: function(...array); But this method is
> not working when the array is associative.
>
> Would not be fine if an array like ['param1'=>'value', 'param2' => 'value']
> would be used in a function like function(param1, param2) regardless of the
> order?
>
> I think it would make our lives is easier. I'd be also happy if you know if
> there is more effective method to achieve the same result.
>
> Thanks,
> Midori
>