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();

preferences:
47.81 ms | 408 KiB | 5 Q