PHP中带有变量参数的函数的线程包装类


Thread Wrapper Class for a Function with variable arguments in PHP

这里的思想是创建一个由函数和参数数组组成的类,并在新线程中调用该函数。

这是到目前为止我的类:

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函数。

从PHP 5.6开始,这是可能的。可以使用…将数组展开为参数列表。像这样的操作符:

<?
class FunctionThread extends Thread {
    public function __construct($fFunction, $aParameters){
        $this->fFunction = $fFunction;
        $this->aParameters = $aParameters;
    }
    public function run(){
        $this->fFunction(... $this->aParmeters);
    }
}
?>

查看更多信息

我认为这个函数应该接受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
        ..
    }
}