3v4l.org

run code in 300+ PHP versions simultaneously
<?php class AssemblyFactory { public const PUMPMETHODS = [ 'modelNumber' => 'fromModelNumber', 'productId' => 'fromProductId' ]; public $pumpFactory; public function __construct () { $this->pumpFactory = new PumpFactory(); } public function makeAssembly(array $params) { $validMethods = array_intersect_key(self::PUMPMETHODS, $params); if (!$validMethods) { throw new \InvalidArgumentException("FAIL"); } else { foreach ($validMethods as $paramKey => $methodName) { return $this->pumpFactory->{$methodName}($params[$paramKey]); } } } } class PumpFactory { public function fromProductId($id) { return "__{$id}__"; } public function fromModelNumber($id) { return "**{$id}**"; } } $factory = new AssemblyFactory(); $tests = [ ['productId' => 33], ['modelNumber' => 'AAA-50'], ['productId' => 1, 'modelNumber' => 'BBB-01'], ['invalidKey' => 'nope'] ]; foreach ($tests as $testParams) { $factory = new AssemblyFactory; echo "Pump = " , $factory->makeAssembly($testParams), "\n"; }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.1rc30.0090.00016.96
8.1rc20.0030.00617.04
8.1rc10.0050.00316.83
8.0.130.0000.00613.39
8.0.120.0020.00516.91
8.0.110.0070.00016.88
8.0.100.0040.00416.80
8.0.90.0050.00516.85
8.0.80.0020.01616.88
8.0.70.0000.00817.00
8.0.60.0040.00416.92
8.0.50.0000.00816.86
8.0.30.0130.00717.35
8.0.20.0180.00917.28
8.0.10.0030.00517.13
8.0.00.0130.00516.89
7.4.260.0070.00016.54
7.4.250.0040.00416.59
7.4.240.0040.00416.51
7.4.230.0000.00716.70
7.4.220.0000.00816.64
7.4.210.0040.01016.58
7.4.200.0000.00716.64
7.4.130.0100.01016.66
7.4.120.0040.01316.45
7.4.110.0070.01016.53
7.4.100.0100.01316.34
7.4.90.0130.00316.77
7.4.80.0120.00919.39
7.4.70.0000.01616.48
7.4.60.0090.00616.51
7.4.50.0100.00716.55
7.4.40.0110.00516.61
7.4.00.0070.00714.56
7.3.330.0030.00313.41
7.3.320.0030.00313.51
7.3.310.0070.00016.42
7.3.300.0060.00016.48
7.3.290.0080.00516.43
7.3.280.0180.00316.44
7.3.260.0100.00816.45
7.3.240.0120.00716.57
7.3.230.0120.00916.70
7.3.210.0040.01416.50
7.3.200.0070.01016.44
7.3.190.0040.01616.46
7.3.180.0110.00616.63
7.3.170.0090.00616.54
7.3.160.0120.00816.57
7.3.70.0100.01314.59
7.3.60.0150.00614.89
7.3.50.0100.00314.90
7.3.40.0100.00314.35
7.3.30.0090.00914.83
7.3.20.0180.00914.43
7.3.10.0090.00614.49
7.3.00.0170.00614.53
7.2.330.0130.01016.49
7.2.320.0110.00616.68
7.2.310.0100.00716.66
7.2.300.0150.00416.42
7.2.290.0110.01116.66
7.2.200.0040.01715.15
7.2.190.0070.00715.19
7.2.180.0100.00315.15
7.2.170.0040.01214.92
7.2.160.0060.00915.02
7.2.150.0090.00514.94
7.2.140.0580.00315.02
7.2.130.0190.00615.17
7.2.120.0140.00614.91
7.2.110.0150.00415.36
7.2.100.0070.01115.10
7.2.90.0070.01015.33
7.2.80.0120.00814.88
7.2.70.0160.01015.23
7.2.60.0120.00615.23
7.2.50.0210.00014.91
7.2.40.0140.00315.22
7.2.30.0090.00815.00
7.2.20.0090.00915.25
7.2.10.0110.01415.03
7.2.00.0090.00615.13
7.1.300.0060.00914.15
7.1.290.0090.00614.06
7.1.280.0040.01113.73
7.1.270.0110.01113.72
7.1.260.0100.00614.08
7.1.250.0100.01014.01

preferences:
22.55 ms | 527 KiB | 12 Q