3v4l.org

run code in 300+ PHP versions simultaneously
<?php if (PHP_VERSION !== '7.2.0alpha2') die('Meh'); function test($label = '') { global $t; $t2 = microtime(1); if ($label) echo str_pad($label . ': ', 32, '.', STR_PAD_RIGHT) . ' ' . 1000 * ($t2 - $t) . 'ms' . "\n"; $t = $t2; } $c = 1; $c2 = 10000; // --------------------- class Meh { function hem() { return 1; } } class MehBag { public $meh1, $meh2, $meh3; function __construct(Meh $meh) { $this->meh1 = $meh; $this->meh2 = $meh; $this->meh3 = $meh; } } $x1 = function (Meh $meh1, Meh $meh2, Meh $meh3) { return $meh1->hem() + $meh2->hem() + $meh3->hem(); }; $x2 = function (MehBag $bag) { return $bag->meh1->hem() + $bag->meh2->hem() + $bag->meh3->hem(); }; // --------------------- test(); for ($i = $c; $i--;) { for ($j = $c2; $j--;) { $rc = new \ReflectionFunction($x1); $rp = $rc->getParameters(); $bag = [ Meh::class => new Meh() ]; $args = []; foreach ($rp as $p) { $pc = $p->getClass(); $name = $pc->name ?? null; if ($name) $args[] = $bag[$name]; } $result1 = $x1(...$args); } } test('ref'); for ($i = $c; $i--;) { for ($j = $c2; $j--;) { $bag = new MehBag(new Meh()); $result2 = $x2($bag); } } test('bag'); var_dump($result1); var_dump($result2);
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.7
Meh

preferences:
63.29 ms | 402 KiB | 34 Q