It doesn't replace call_user_func_array(). It replaces func_get_args(). It's just a way to pass an unknown number of arguments to any function (packing) or retrieving them from the function (unpacking). See the examples and explanation in the announcement: http://php.net/manual/en/migration56.new-features.php
Jan 27, 2019
2
Level 75
PHP general question
This works:
if (array_key_exists($key_to_check, $routes)) {
$uparts = explode('@', $routes[$key_to_check]);
$controller = isset($uparts[0]) ? $uparts[0] : null;
$action = isset($uparts[1]) ? $uparts[1] : null;
call_user_func_array(array($controller, $action), $last);
}
But I am trying to convert to variadic (splat operator), and the below does not work:
if (array_key_exists($key_to_check, $routes)) {
$uparts = explode('@', $routes[$key_to_check]);
$controller = isset($uparts[0]) ? $uparts[0] : null;
$action = isset($uparts[1]) ? $uparts[1] : null;
$controller->$action(...$last);
}
Anyone know how to properly replace the call_user_func_array with splat?
Note, $last is just the parameters being passed.
Level 67
Please or to participate in this conversation.