'PHP, how to pass func-get-args values to another function as list of arguments?

I want to create a function (my_function()) getting unlimited number of arguments and passing it into another function (call_another_function()).

function my_function() {    
   another_function($arg1, $arg2, $arg3 ... $argN);    
}

So, want to call my_function(1,2,3,4,5) and get calling another_function(1,2,3,4,5)

I know that I shoud use func_get_args() to get all function arguments as array, but I don't know how to pass this arguments to another function.

Thank you.

php


Solution 1:[1]

Use call_user_func_array like

call_user_func_array('another_function', func_get_args());

Solution 2:[2]

It's not yet documented but you might use reflection API, especially invokeArgs.

(maybe I should have used a comment rather than a full post)

Solution 3:[3]

I have solved such a problem with the ...$args parameter in the function.

In my case, it was arguments forwarding to the parent construction call.

public function __construct(...$args)
{
    parent::__construct(...$args);
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Pentium10
Solution 2 Aif
Solution 3 D.Che