Я провел весь пример https://github.com/krakjoe/pthreads/tree/seven/examples
в CLI. После выполнения каждого из них я получаю PHP Fatal error
и Fatal error
, в дополнение к ожидаемому результату. К примеру, в этом случае https://github.com/krakjoe/pthreads/blob/seven/examples/ClosureFuture.php
я получаю:php pthreads: «PHP Fatal error», «Fatal error» в CLI
object(Volatile)#6 (2) {
[0]=>
string(5) "Hello"
[1]=>
string(5) "World"
}
array(2) {
[0]=>
string(5) "Hello"
[1]=>
string(5) "World"
}
PHP Fatal error: Cannot declare class Future, because the name is already in use in /var/www/test/index1.php on line 42
Fatal error: Cannot declare class Future, because the name is already in use in /var/www/test/index1.php on line 42
Во всех примере ошибка произошла, когда расширенный класс закрыт.
Знаете ли вы причину этих ошибок и как их исправить? Любая помощь будет оценена по достоинству.
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
В PHP 7.0.0RC4 – majidfathi69
Спасибо за ответ, моя текущая версия php - 5.5.8, а также я тестировал ее на версиях 7.0.0RC4, 7.0.0RC3, 7.0.0RC2. – majidfathi69