脚本宝典收集整理的这篇文章主要介绍了php – 将未定义的参数数转发给另一个函数,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
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,但不要破坏args,只需将剩余的args数组传递给call_user_func_array
call_user_func_array('anotherFunction',$args);
用于创建对象
用途:ReflectionClass::newInstanceArgs
$refclass = new ReflectionClass('yourclassname'); $obj = $refClass->newInstanceArgs($yourConstructorArgs);
或者:ReflectionClass::newinstance
$refClass = new ReflectionClass('yourClassName'); $obj = call_user_func_array(array($refClass,'newInstance'),$yourConstructorArgs);
以上是脚本宝典为你收集整理的php – 将未定义的参数数转发给另一个函数全部内容,希望文章能够帮你解决php – 将未定义的参数数转发给另一个函数所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。