3v4l.org

run code in 300+ PHP versions simultaneously
<?php class FakePromise { public $value; public function __construct($value) { $this->value = $value; } public function getValue() { return $this->value; } } function coroutine() { $a = yield new FakePromise(1); $b = yield new FakePromise(2); return $a+$b; } function makeRunnable($fn) { return function(...$args) use ($fn) { $gen = call_user_func_array($fn, $args); while ($gen->valid()) { $current = $gen->current(); if ($gen === null) { $current = $gen->getReturn(); } if ($current instanceof FakePromise) { $gen->send($current->getvalue()); } else { $gen->send($current); // handle none Promises } } return $gen->getReturn(); }; } $fn = makeRunnable('coroutine'); echo call_user_func($fn);
Output for 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
3
Output for 5.6.0 - 5.6.40
Parse error: syntax error, unexpected 'new' (T_NEW) in /in/k91RV on line 15
Process exited with code 255.

preferences:
167.55 ms | 401 KiB | 290 Q