3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function fooGenerator() { $range = range(0, 1000); try { foreach ($range as $key) { yield $key; } } finally { var_dump($this, 'Closed!'); } } $iterator = fooGenerator(); foreach ($iterator as $key) { break; }
based on pjk7Y
Output for 7.2.0
Output for 7.1.0 - 7.1.10
Fatal error: Uncaught Error: Using $this when not in object context in /in/ot7F5:10 Stack trace: #0 {main} thrown in /in/ot7F5 on line 10
Process exited with code 255.
Output for 5.5.24 - 7.0.20
Notice: Undefined variable: this in /in/ot7F5 on line 10 NULL string(7) "Closed!"
Output for 5.4.10 - 5.4.45
Parse error: syntax error, unexpected '$key' (T_VARIABLE) in /in/ot7F5 on line 7
Process exited with code 255.
Output for 5.3.20 - 5.3.29
Parse error: syntax error, unexpected T_VARIABLE in /in/ot7F5 on line 7
Process exited with code 255.