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 0k38U
Output for 7.2.0
First: 0.068236827850342 Second: 0.068158149719238
Output for 7.1.10
First: 0.061882019042969 Second: 0.073585987091064
Output for 7.1.7
First: 0.059312105178833 Second: 0.066092014312744
Output for 7.1.6
First: 0.095571041107178 Second: 0.08469295501709
Output for 7.1.5
First: 0.063350915908813 Second: 0.072870969772339
Output for 7.1.0
First: 0.078792095184326 Second: 0.076618909835815
Output for 7.0.20
First: 0.05935001373291 Second: 0.062040090560913
Output for 7.0.10
First: 0.10571718215942 Second: 0.093211889266968
Output for 7.0.9
First: 0.070158958435059 Second: 0.07387900352478
Output for 7.0.8
First: 0.057173013687134 Second: 0.07091498374939
Output for 7.0.7
First: 0.059302091598511 Second: 0.06821084022522
Output for 7.0.6
First: 0.0691819190979 Second: 0.072582960128784
Output for 7.0.5
First: 0.06860089302063 Second: 0.076956987380981
Output for 7.0.4
First: 0.055762052536011 Second: 0.069659948348999
Output for 7.0.3
First: 0.04947304725647 Second: 0.065530061721802
Output for 7.0.2
First: 0.053617000579834 Second: 0.069031000137329
Output for 7.0.1
First: 0.068604946136475 Second: 0.071491003036499
Output for 7.0.0
First: 0.062762975692749 Second: 0.070092916488647
Output for 5.6.0 - 5.6.28
Parse error: syntax error, unexpected '(' in /in/e0qoK on line 12
Process exited with code 255.
Output for 5.5.0 - 5.5.38
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/e0qoK on line 10
Process exited with code 255.