php – 将未定义的参数数转发给另一个函数
发布时间:2020-05-25 09:03:51 所属栏目: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
我将用一个接受任意数量函数的简单函数来解释这个问题 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); (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |