PHP中具有可变参数的函数的线程包装器类
这里的想法是创建一个类,该类使用函数和参数数组构造,并在新线程中调用该函数 这是我目前的课程:PHP中具有可变参数的函数的线程包装器类,php,arrays,multithreading,pthreads,variadic-functions,Php,Arrays,Multithreading,Pthreads,Variadic Functions,这里的想法是创建一个类,该类使用函数和参数数组构造,并在新线程中调用该函数 这是我目前的课程: class FunctionThread extends Thread { public function __construct($fFunction, $aParameters){ $this->fFunction = $fFunction; $this->aParameters = $aParameters; } publ
class FunctionThread extends Thread {
public function __construct($fFunction, $aParameters){
$this->fFunction = $fFunction;
$this->aParameters = $aParameters;
}
public function run(){
$this->fFunction($this->aParmeters[0], $this->aParmeters[1], ...);
}
}
显然run函数不正确,这就引出了我的问题:
假设数组保证有适当数量的元素来匹配正在调用的函数,那么如何使用数组中存储的未知数量的参数调用PHP中的函数
编辑:
此外,我无法访问给定函数的内容,因此无法对其进行编辑
编辑2:我正在寻找类似scheme的curry函数的东西。我认为该函数应该接受arg数组
class FunctionThread extends Thread {
public function __construct($fFunction, $aParameters){
$this->fFunction = $fFunction;
$this->aParameters = $aParameters;
}
public function run(){
$this->fFunction($this->aParmeters);
}
public function fFunction($arr){
$var0 = $arr[0];
$var1 = $arr[1];
...
do
..
}
}
从PHP5.6开始,这是可能的。可以使用。。。像这样的经营者:
<?
class FunctionThread extends Thread {
public function __construct($fFunction, $aParameters){
$this->fFunction = $fFunction;
$this->aParameters = $aParameters;
}
public function run(){
$this->fFunction(... $this->aParmeters);
}
}
?>
有关更多信息,请参见我正试图完全抽象掉该函数。如果我可以访问该函数的源代码,我会这样做,但不幸的是,这需要与我无法访问的API进行交互。谢谢。我正在寻找类似提取函数的东西。但这将进入该功能的范围。