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) { $this->add($item); } } public function add(A $item) { $this->collection[] = $item; } }; $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;
Output for 7.2.0
First: 0.058972835540771 Second: 0.19511389732361
Output for 7.1.10
First: 0.063393115997314 Second: 0.26932311058044
Output for 7.1.7
First: 0.10296893119812 Second: 0.25419592857361
Output for 7.1.6
First: 0.09027099609375 Second: 0.20090794563293
Output for 7.1.5
First: 0.073168992996216 Second: 0.19012308120728
Output for 7.1.0
First: 0.08091402053833 Second: 0.24066686630249
Output for 7.0.20
First: 0.060833930969238 Second: 0.23618793487549
Output for 7.0.10
First: 0.067309141159058 Second: 0.19799208641052
Output for 7.0.9
First: 0.052650928497314 Second: 0.19559192657471
Output for 7.0.8
First: 0.053849935531616 Second: 0.19437503814697
Output for 7.0.7
First: 0.055635929107666 Second: 0.19365501403809
Output for 7.0.6
First: 0.063246011734009 Second: 0.19306707382202
Output for 7.0.5
First: 0.048233032226562 Second: 0.20037508010864
Output for 7.0.4
First: 0.070327997207642 Second: 0.20505809783936
Output for 7.0.3
First: 0.063218116760254 Second: 0.19978904724121
Output for 7.0.2
First: 0.064158916473389 Second: 0.19775700569153
Output for 7.0.1
First: 0.055621862411499 Second: 0.19680905342102
Output for 7.0.0
First: 0.065875053405762 Second: 0.19408798217773
Output for 5.6.0 - 5.6.25
Parse error: syntax error, unexpected '(' in /in/uoGTl 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/uoGTl on line 10
Process exited with code 255.