jjzjj

invokeArgs

全部标签

php - 通过引用将参数可移植地传递给 PHP 的 ReflectionMethod::invokeArgs

似乎用词不当,因为在PHP5.3中不推荐使用引用传递...无论如何,我想做的是使用反射编写一个单元测试框架,它允许您将参数传递给需要的方法一个引用。例如classBar{functionTestMethod($arg1,&$result){$result='hello';returntrue;}}$rc=newReflectionMethod('Bar','TestMethod');$return_val=$rc->invokeArgs($instance,$arguments);现在,我在http://www.phwinfo.com/forum/comp-lang-php/27331

php, invokeArgs : parameters changed, 怎么返回呢?

首先,我要测试一个功能:privatefunctiontestMe(array&$output){$output['a']=3;//$$$$$outputgetschanges}我做了一个小方法让它公开,然后调用:publicstaticfunctionmakePublicAndCall($objectInstance,$methodname){$ref=newReflectionMethod(get_class($objectInstance),$methodname);$ref->setAccessible(true);$params=array();for($i=2+1;$iin

php - 我可以将关联数组作为参数传递给 ReflectionMethod::invokeArgs 吗?

是否可以在ReflectionMethod::invokeArgs中将参数作为关联数组传递?这将允许我以不同于声明的顺序传递参数。例如:classA{publicfunctionsomeMethod($a,$b){returnsprintf("a-%s,b-%s",$a,$b);}}$rm=newReflectionMethod('A','someMethod');echo$rm->invokeArgs(newA(),array('b'=>1,'a'=>2)); 最佳答案 您可以通过覆盖invokeArgs方法并实现您需要的功能来实