<?php
/* A tasks job is to count from 0 to $limit */
class Task {
public function __construct($limit) {
$this->limit = ($limit + 1) * 100;
}
public function doWork() {
$this->position++;
}
public function hasWork() {
return $this->position <= $this->limit;
}
public function getPosition() {
return $this->position;
}
private $position = 0;
private $limit = 0;
}
/* create three tasks */
$tasks[] = new Task(0);
$tasks[] = new Task(1);
$tasks[] = new Task(3);
/* do some work */
function work($tasks) {
foreach ($tasks as $task)
if ($task->hasWork())
$task->doWork();
}
/* detect more work to do */
function finished($tasks) {
foreach ($tasks as $task) {
if ($task->hasWork())
return false;
}
return true;
}
/* helper for printing positions */
function positions($tasks) {
$positions = [];
foreach ($tasks as $task) {
$positions[] =
$task->hasWork() ?
$task->getPosition() : "-";
}
return $positions;
}
/* execute tasks asynchronously */
while (!finished($tasks)) {
vprintf(
"% 4s % 4s % 4s\n", positions($tasks));
work($tasks);
}
?>
Parse error: syntax error, unexpected '[' in /in/dvPVA on line 49
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/dvPVA on line 49
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/dvPVA on line 5
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/dvPVA on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/dvPVA on line 5
Process exited with code 255.