将未定义数量的参数转发给另一个函数


Forward undefined number of arguments to another function

我将用一个接受任意数量函数的简单函数来解释这个问题

function abc() {
   $args = func_get_args();
   //Now lets use the first parameter in something...... In this case a simple echo
   echo $args[0];
   //Lets remove this first parameter 
   unset($args[0]); 
   //Now I want to send the remaining arguments to different function, in the same way as it received
   .. . ...... BUT NO IDEA HOW TO . ..................
   //tried doing something like this, for a work around
   $newargs = implode(",", $args); 
   //Call Another Function
   anotherFUnction($newargs); //This function is however a constructor function of a class
   // ^ This is regarded as one arguments, not mutliple arguments....
}

我希望问题现在已经清楚了,针对这种情况,我们要做什么?

更新

我忘了提到我调用的下一个函数是另一个类的构造函数类。类似的东西

$newclass = new class($newarguments);

用于简单函数调用

使用call_user_func_array,但不要内爆参数,只需将剩余参数的数组传递给call_user_func_array

call_user_func_array('anotherFunction', $args);

用于对象创建

使用:反射类::newInstanceArgs

$refClass = new ReflectionClass('yourClassName');
$obj = $refClass->newInstanceArgs($yourConstructorArgs);

或:ReflectionClass::newinstance

$refClass = new ReflectionClass('yourClassName');
$obj = call_user_func_array(array($refClass, 'newInstance'), $yourConstructorArgs);