3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Item { private $id; public function __construct(int $id) { $this->id = $id; } public function id() : int { return $this->id; } } class Items implements IteratorAggregate { private $items = []; public function __construct(Item ...$items) { $this->items = $items; } public function getIterator() : Generator { yield from $this->items; } } class Collection extends IteratorIterator { /** @var Items */ public function __construct(Items $items) { parent::__construct($items); } public function current() : Item { return parent::current(); } } $items = []; for ($i=0; $i<10; $i++) { $items[] = new Item($i); } $collection = new Collection(new Items(...$items)); foreach ($collection as $item) { printf("\tClass: %s. Calling id() method returns %d (%s)\n", get_class($item), $item->id(), gettype($item->id())); }
based on YcKua
Output for 7.0.0 - 7.3.0beta1
Class: Item. Calling id() method returns 0 (integer) Class: Item. Calling id() method returns 1 (integer) Class: Item. Calling id() method returns 2 (integer) Class: Item. Calling id() method returns 3 (integer) Class: Item. Calling id() method returns 4 (integer) Class: Item. Calling id() method returns 5 (integer) Class: Item. Calling id() method returns 6 (integer) Class: Item. Calling id() method returns 7 (integer) Class: Item. Calling id() method returns 8 (integer) Class: Item. Calling id() method returns 9 (integer)
Output for hhvm-3.13.2 - 3.21.0
Fatal error: Uncaught Error: Parameter $items is variadic and has a type constraint (Item); variadic params with type constraints are not supported in non-Hack files in /in/OH18b:16 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.11.1 - 3.12.14
Fatal error: Uncaught Error: Parameter $items is variadic and has a type constraint (Item); variadic params with type constraints are not supported in /in/OH18b:16 Stack trace: #0 {main}
Process exited with code 255.
Output for hhvm-3.10.1
Fatal error: Syntax only allowed in Hack files (<?hh) or with -v Eval.EnableHipHopSyntax=true in /in/OH18b on line 8
Process exited with code 255.
Output for 5.1.0 - 5.6.30
Parse error: syntax error, unexpected ':', expecting ';' or '{' in /in/OH18b on line 8
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected ':', expecting '{' or ';' in /in/OH18b on line 8
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/OH18b on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/OH18b on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/OH18b on line 3
Process exited with code 255.