【发布时间】:2015-10-10 16:33:00
【问题描述】:
我在 CLI 中运行了https://github.com/krakjoe/pthreads/tree/seven/examples 的所有示例。
执行每一项后,除了预期结果外,我还得到 PHP Fatal error 和 Fatal error 。
例如在这种情况下https://github.com/krakjoe/pthreads/blob/seven/examples/ClosureFuture.php 我会得到:
object(Volatile)#6 (2) {
[0]=>
string(5) "Hello"
[1]=>
string(5) "World"
}
array(2) {
[0]=>
string(5) "Hello"
[1]=>
string(5) "World"
}
PHP 致命错误:无法声明类 Future,因为该名称已在第 42 行的 /var/www/test/index1.php 中使用
致命错误:无法声明类 Future,因为该名称已在第 42 行的 /var/www/test/index1.php 中使用
在扩展类关闭时发生的所有示例错误。
您知道这些错误的原因以及如何纠正它们吗? 任何帮助将不胜感激。
class Future extends Thread {
private function __construct(Closure $closure, array $args = []) {
$this->closure = $closure;
$this->args = $args;
}
public function run() {
$this->synchronized(function() {
$this->result =
($this->closure)(...$this->args);
$this->notify();
});
}
public function getResult() {
return $this->synchronized(function(){
while (!$this->result)
$this->wait();
return $this->result;
});
}
public static function of(Closure $closure, array $args = []) {
$future =
new self($closure, $args);
$future->start();
return $future;
}
protected $owner;
protected $closure;
protected $args;
protected $result;
}//line 42
【问题讨论】: