3v4l.org

run code in 300+ PHP versions simultaneously
<?php class X { function __construct($id, $gen) { $this->id = $id; $this->gen = $gen; } function __destruct() { echo "__destruct $this->id\n"; var_dump($this->gen->current()); var_dump($this->gen->key()); echo "\n\n"; } } function make($id, $self) { return new X($id, $self); } function gen() { $self = yield (0); echo "After yield 0\n"; $k = make('key', $self); $v = make('value', $self); yield $k => $v; unset($k, $v); echo "After yield X\n"; yield 12; } $a = gen(); var_dump($a->current()); $a->send($a); var_dump($a->current()); $a->next();
Output for 7.0.0 - 7.0.33, 7.3.0, 7.3.21, 7.3.31 - 7.3.32, 7.4.5 - 7.4.6, 7.4.9 - 7.4.10, 7.4.15 - 7.4.16, 7.4.22 - 7.4.25, 7.4.27, 8.0.6, 8.0.8 - 8.0.11, 8.0.14, 8.0.19, 8.0.21 - 8.0.22, 8.1.0 - 8.1.10
int(0) After yield 0 object(X)#3 (2) { ["id"]=> string(5) "value" ["gen"]=> object(Generator)#1 (0) { } } After yield X __destruct value object(X)#3 (2) { ["id"]=> string(5) "value" ["gen"]=> object(Generator)#1 (0) { } } object(X)#2 (2) { ["id"]=> string(3) "key" ["gen"]=> object(Generator)#1 (0) { } } __destruct key
Process exited with code 139.
Output for 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.16 - 7.3.20, 7.3.23 - 7.3.30, 7.3.33, 7.4.0 - 7.4.4, 7.4.7 - 7.4.8, 7.4.11 - 7.4.14, 7.4.20 - 7.4.21, 7.4.26, 7.4.28 - 7.4.30, 8.0.0 - 8.0.5, 8.0.7, 8.0.12 - 8.0.13, 8.0.15 - 8.0.18, 8.0.20, 8.0.23
int(0) After yield 0 object(X)#3 (2) { ["id"]=> string(5) "value" ["gen"]=> object(Generator)#1 (0) { } } After yield X __destruct value object(X)#3 (2) { ["id"]=> string(5) "value" ["gen"]=> object(Generator)#1 (0) { } } object(X)#2 (2) { ["id"]=> string(3) "key" ["gen"]=> object(Generator)#1 (0) { } } __destruct key *RECURSION* object(X)#2 (2) { ["id"]=> string(3) "key" ["gen"]=> object(Generator)#1 (0) { } }
Output for 5.5.0 - 5.5.38, 5.6.0 - 5.6.38
Parse error: syntax error, unexpected '(' in /in/LUq3k on line 16
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$k' (T_VARIABLE) in /in/LUq3k on line 20
Process exited with code 255.

preferences:
53.07 ms | 413 KiB | 5 Q