3v4l.org

run code in 300+ PHP versions simultaneously
<?php macro async: Awaitable { // $$ is a (Closure(): mixed) return Psl\Async\run($$); } macro await: Awaitable { return Psl\Async\await($$()); } macro await_all: Awaitable { return Psl\Async\all($$()); } macro foo: int { return 1; } macro bar: mixed { return $$(); } macro main: never { $$(); exit(0); } main! { $awaitable = async! $server->nextConnection(); $client = await! $awaitable; [$response1, $response2] = await_all! [ async! $client->request('GET', '/foo'), async! $client->request('GET', '/bar'), ]; // equivelent to: [$response1, $response2] = Psl\Async\all([ Psl\Async\run(fn() => $client->request('GET', '/foo')), Psl\Async\run(fn() => $client->request('GET', '/bar')), ]); $foo = foo! { die('this is never called!'); }; $bar = bar! { // this block will capture variables from parent scope. return 4 + $foo; }; var_dump($bar); };
Output for 8.0.1 - 8.0.18, 8.1.0 - 8.1.6
Parse error: syntax error, unexpected identifier "async" in /in/h2X79 on line 3
Process exited with code 255.
Output for 7.4.0 - 7.4.29
Parse error: syntax error, unexpected 'async' (T_STRING) in /in/h2X79 on line 3
Process exited with code 255.

preferences:
150.06 ms | 1303 KiB | 6 Q