可能重复:
PHP, how to pass func-get-args values to another function as list of arguments?具有未知数量参数的方法是否可以调用具有未知数量参数的另一种方法?
我有一个基类的方法,可以采取任意数量的参数。此方法需要调用第三方对象的方法,该方法可以使用传递给第一个方法的参数获取任意数量的参数。
我提到它是一个第三方对象,被调用来强化被调用方法的签名不能被修改为接受数组或对象的约束。
例子:
<?php
class Example {
private $thirdPartyObject = null;
public function methodOne() {
$arguments = func_get_args();
$this->thirdPartyObject = new ThirdPartyObject();
$this->externalObject->methodName(/* pass on variable number of arguments here */);
}
}
$exampleObject = new Example();
$exampleObject->methodOne('a', 'b', 'c');
如果我们事先知道被传递到Example->methodOne()
参数的个数,然后我们可以在相同数量的参数传递给ThirdPartyObject->methodName()
。
如果我们事先不知道传递给Example->methodOne()
的参数的数量,我们可以将这些参数传递给ThirdPartyObject->methodName()
吗?
在这种情况下,ThirdPartyObject->methodName()
被称为与一个或多个参数,如:
<?php
$thirdPartyObject = new ThirdPartyObject();
$thirdPartyObject->methodName('a');
$thirdPartyObject->methodName('a', 'b');
$thirdPartyObject->methodName('a', /* ... */, 'N');
您是否尝试过这个?:[http://stackoverflow.com/questions/2126778/php-how-to-pass-func-get-args - 值对另一个功能-AS--的-参数列表(http://stackoverflow.com/questions/2126778/php-how-to-pass-func-get-args-values-to-another- function-as-list-of-arguments) – Zbigniew 2012-07-16 15:11:38
@des:谢谢你的建议,我的搜索没有找到它。 – 2012-07-16 15:23:56