3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class A { } class First { protected $collection; public function __construct(array $items) { $this->collection = (function (A ...$items) { return $items; })(...$items); } }; class Second { protected $collection; public function __construct(array $items) { foreach ($items as $item) { if (!($item instanceof A) { throw new Exception(); } } $collection = $items; } }; $given = [ new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), new A(), ]; $start = microtime(true); for ($i = 0; $i < 10000; $i++) { new First($given); } echo "First: " . (microtime(true) - $start) . PHP_EOL; $start = microtime(true); for ($i = 0; $i < 10000; $i++) { new Second($given); } echo "Second: " . (microtime(true) - $start) . PHP_EOL;
based on uoGTl
Output for 7.0.0 - 7.0.2
Parse error: syntax error, unexpected 'throw' (T_THROW) in /in/0k38U on line 22
Process exited with code 255.
Output for 5.6.8 - 5.6.17
Parse error: syntax error, unexpected '(' in /in/0k38U on line 12
Process exited with code 255.
Output for 5.4.12 - 5.5.31
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/0k38U on line 10
Process exited with code 255.
Output for 5.3.22 - 5.3.29
Parse error: syntax error, unexpected '.', expecting '&' or T_VARIABLE in /in/0k38U on line 10
Process exited with code 255.