3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Person { var $name; var $age; function __construct($name, $age) { $this->name = $name; $this->age = $age; } } $a = new ArrayIterator([ new Person("Christoph", 15), new Person("John", 42), new Person("Foobar", 25) ]); function first_match(\Iterator $iterator, callable $callback) { foreach ($iterator as $key => $value) { if ($callback($value, $key)) { yield $key => $value; break; } } } $firstOver18 = function($person) { return $person->age >= 18; }; var_dump(first_match($a, $firstOver18)->current());
Output for 5.5.0 - 5.6.28, hhvm-3.12.0, 7.0.0 - 7.1.0
object(Person)#3 (2) { ["name"]=> string(4) "John" ["age"]=> int(42) }
Output for hhvm-3.10.0
Fatal error: Uncaught exception 'Exception' with message 'Need to call next() first' in /in/V9uQ1:36 Stack trace: #0 /in/V9uQ1(36): Generator->current() #1 {main}
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '$key' (T_VARIABLE) in /in/V9uQ1 on line 25
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.3 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/V9uQ1 on line 15
Process exited with code 255.
Output for 5.1.0 - 5.1.2
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/V9uQ1 on line 5 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/V9uQ1 on line 6 Parse error: syntax error, unexpected '[', expecting ')' in /in/V9uQ1 on line 15
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/V9uQ1 on line 5 Strict Standards: var: Deprecated. Please use the public/private/protected modifiers in /in/V9uQ1 on line 6 Parse error: parse error, unexpected '[', expecting ')' in /in/V9uQ1 on line 15
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected '[', expecting ')' in /in/V9uQ1 on line 15
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `')'' in /in/V9uQ1 on line 15
Process exited with code 255.