3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Request { public $answer = 42; public function __construct() { echo 'Request created', PHP_EOL; } } class DI { protected $shared = []; protected $definitions = []; public function __construct() {} public function set($name, $definition, $shared = false) { if($shared) { if(isset($shared[$name])) { throw new Exception("Definition '$name' is already set. Use DI::remove('$name') to remove it."); } $this->shared[$name] = $definition; } else { if(isset($definitions[$name])) { throw new Exception("Definition '$name' is already set. Use DI::remove('$name') to remove it."); } $this->definitions[$name] = $definition; } } public function getRaw($name) { if(!isset($this->definitions[$name])) { throw new Exception("Definition '$name' is not set. Use DI::set('$name', <definition>) to set it."); } return $this->definitions[$name]; } public function get($name) { $definition = $this->getRaw($name); if(is_callable($definition)) return $definition(); if(class_exists($definition)) return new $definition(); } public function getShared($name) { if(!isset($this->shared[$name])) { throw new Exception("Shared definition '$name' is not set. Use DI::set('$name', <definition>, true) to set it."); } $shared = $this->shared[$name]; if(is_callable($shared)) $this->shared[$name] = $shared(); else if(is_string($shared) && class_exists($shared)) $this->shared[$name] = new $shared(); return $this->shared[$name]; } } $di = new DI(); //Using an anonymous function $di->set('request1', function(){ return new Request(); }); //Using an anonymous function $di->set('request2', 'Request', true); $request = $di->getShared('request2'); $request->answer = 5; var_dump($di->getShared('request2')); $request = $di->getShared('request1'); $request->answer = 5; var_dump($di->getShared('request1'));

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.3.60.0070.00718.43
8.3.50.0120.00621.16
8.3.40.0090.00918.77
8.3.30.0070.00719.09
8.3.20.0080.00020.29
8.3.10.0000.00721.76
8.3.00.0040.00419.51
8.2.180.0040.01116.63
8.2.170.0130.00922.96
8.2.160.0120.00319.38
8.2.150.0050.00324.18
8.2.140.0080.00024.66
8.2.130.0000.00926.16
8.2.120.0000.00722.27
8.2.110.0030.00622.07
8.2.100.0040.00817.84
8.2.90.0000.00819.21
8.2.80.0050.00317.97
8.2.70.0000.00817.50
8.2.60.0060.00317.93
8.2.50.0050.00518.07
8.2.40.0040.00419.94
8.2.30.0030.00618.10
8.2.20.0080.00017.90
8.2.10.0000.00718.19
8.2.00.0040.00417.88
8.1.280.0040.01325.92
8.1.270.0040.00422.27
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0060.00323.88
8.1.230.0040.00719.00
8.1.220.0050.00317.79
8.1.210.0030.00518.77
8.1.200.0070.00317.11
8.1.190.0030.00617.25
8.1.180.0040.00418.10
8.1.170.0040.00418.71
8.1.160.0040.00422.17
8.1.150.0040.00418.95
8.1.140.0050.00217.41
8.1.130.0000.00817.88
8.1.120.0000.00717.53
8.1.110.0040.00417.55
8.1.100.0000.00817.57
8.1.90.0000.00817.42
8.1.80.0070.00017.50
8.1.70.0070.00017.53
8.1.60.0060.00317.66
8.1.50.0040.00417.47
8.1.40.0040.00417.53
8.1.30.0040.00417.60
8.1.20.0000.00817.64
8.1.10.0040.00417.60
8.1.00.0030.00517.55
8.0.300.0040.00418.77
8.0.290.0030.00516.88
8.0.280.0040.00418.41
8.0.270.0070.00017.25
8.0.260.0000.00617.31
8.0.250.0080.00017.06
8.0.240.0000.00817.05
8.0.230.0040.00417.02
8.0.220.0000.00717.04
8.0.210.0070.00017.05
8.0.200.0000.00716.94
8.0.190.0030.00516.97
8.0.180.0000.00717.04
8.0.170.0050.00317.00
8.0.160.0000.00717.04
8.0.150.0030.00516.92
8.0.140.0030.00416.94
8.0.130.0030.00313.50
8.0.120.0000.00716.99
8.0.110.0000.00817.04
8.0.100.0040.00416.96
8.0.90.0040.00416.97
8.0.80.0000.01516.96
8.0.70.0000.00717.13
8.0.60.0070.00017.03
8.0.50.0030.00516.98
8.0.30.0150.00517.14
8.0.20.0110.01517.40
8.0.10.0060.00317.20
8.0.00.0090.00816.88
7.4.330.0030.00315.14
7.4.320.0000.00716.51
7.4.300.0000.00616.54
7.4.290.0000.00816.58
7.4.280.0070.00016.48
7.4.270.0020.00516.55
7.4.260.0050.00316.52
7.4.250.0000.00716.59
7.4.240.0050.00216.66
7.4.230.0000.00716.66
7.4.220.0030.01416.73
7.4.210.0060.00916.70
7.4.200.0030.00316.46
7.4.160.0070.01016.43
7.4.150.0100.01017.40
7.4.140.0130.00817.86
7.4.130.0120.00616.70
7.4.120.0080.00916.72
7.4.110.0070.01616.64
7.4.100.0060.01116.57
7.4.90.0060.01216.73
7.4.80.0090.00919.39
7.4.70.0070.01016.55
7.4.60.0090.00816.58
7.4.50.0000.00616.46
7.4.40.0120.00616.35
7.4.30.0140.00316.41
7.4.00.0040.01114.66
7.3.330.0020.00313.50
7.3.320.0030.00313.48
7.3.310.0070.00016.54
7.3.300.0050.00316.34
7.3.290.0090.00816.44
7.3.280.0080.00816.46
7.3.270.0050.01417.40
7.3.260.0070.01016.70
7.3.250.0120.00516.64
7.3.240.0040.01516.68
7.3.230.0060.01416.52
7.3.210.0130.00316.50
7.3.200.0140.00316.54
7.3.190.0150.00316.49
7.3.180.0060.01016.62
7.3.170.0090.00816.55
7.3.160.0120.00416.71
7.2.330.0140.00716.72
7.2.320.0090.00916.86
7.2.310.0100.01016.43
7.2.300.0120.00616.83
7.2.290.0100.01016.89
7.2.60.0060.00617.14
7.2.50.0040.00417.02
7.2.00.0030.01019.39
7.1.200.0060.00615.58
7.1.100.0070.00318.11
7.1.70.0070.00716.91
7.1.60.0140.01119.11
7.1.50.0130.01934.90
7.1.00.0070.07322.35
7.0.200.0070.00316.79
7.0.140.0030.07321.98
7.0.60.0030.08019.99
7.0.50.0130.08017.92
7.0.40.0070.08720.18
7.0.30.0430.05720.19
7.0.20.0470.07020.23
7.0.10.0100.08320.21
7.0.00.0100.07320.30
5.6.280.0000.07720.91
5.6.210.0130.07320.58
5.6.200.0030.08318.18
5.6.190.0100.04020.52
5.6.180.3430.04720.49
5.6.170.0170.06320.52
5.6.160.0030.05320.59
5.6.150.0070.07718.13
5.6.140.0070.07018.18
5.6.130.0030.05018.22
5.6.120.0070.05021.00
5.6.110.0030.08721.01
5.6.100.0100.08021.10
5.6.90.0030.08321.02
5.6.80.0070.08020.30
5.6.70.4470.03320.41
5.5.350.0030.06720.45
5.5.340.0070.08318.02
5.5.330.0130.03020.44
5.5.320.2770.04320.26
5.5.310.0200.07720.20
5.5.300.0030.08718.02
5.5.290.0030.05018.09
5.5.280.0100.08020.75
5.5.270.0030.08720.86
5.5.260.0070.08020.88
5.5.250.0030.04320.70
5.5.240.0230.06320.17
5.4.450.0800.05719.56
5.4.440.0600.06319.16
5.4.430.0230.05319.44
5.4.420.0670.00019.51
5.4.410.0670.00019.32
5.4.400.0630.00018.91
5.4.390.0630.00019.04
5.4.380.0700.00019.26
5.4.370.0630.00019.16
5.4.360.0630.00019.14
5.4.350.0730.00019.16
5.4.340.0040.04512.03
5.4.320.0110.03212.53
5.4.310.0070.03712.52
5.4.300.0090.03512.52
5.4.290.0050.04012.52
5.4.280.0040.04312.41
5.4.270.0090.03612.41
5.4.260.0060.05112.42
5.4.250.0050.03912.42
5.4.240.0050.03812.42
5.4.230.0070.03812.41
5.4.220.0080.03612.41
5.4.210.0080.04612.41
5.4.200.0100.04612.41
5.4.190.0080.03512.40
5.4.180.0070.03512.40
5.4.170.0070.03612.42
5.4.160.0030.03912.41
5.4.150.0050.03712.41
5.4.140.0050.03812.09
5.4.130.0110.03212.08
5.4.120.0050.03612.03
5.4.110.0040.03712.04
5.4.100.0040.03712.03
5.4.90.0060.03712.04
5.4.80.0040.04112.04
5.4.70.0060.03712.03
5.4.60.0070.03612.03
5.4.50.0100.04212.03
5.4.40.0070.03412.02
5.4.30.0030.03912.01
5.4.20.0070.03612.01
5.4.10.0080.03412.02
5.4.00.0060.03711.51
5.3.290.0060.04312.80
5.3.280.0050.03912.71
5.3.270.0080.03712.72
5.3.260.0030.04612.72
5.3.250.0050.03712.72
5.3.240.0070.03612.72
5.3.230.0070.03812.71
5.3.220.0060.03812.68
5.3.210.0060.03812.68
5.3.200.0050.03712.68
5.3.190.0070.03612.67
5.3.180.0060.03612.68
5.3.170.0050.03712.67
5.3.160.0100.03212.68
5.3.150.0020.04112.67
5.3.140.0060.03712.66
5.3.130.0070.03812.66
5.3.120.0060.03812.66
5.3.110.0100.03912.66
5.3.100.0050.03712.13
5.3.90.0040.04512.11
5.3.80.0070.04012.09
5.3.70.0100.04312.09
5.3.60.0130.04112.08
5.3.50.0090.03412.02
5.3.40.0070.03512.02
5.3.30.0070.04711.98
5.3.20.0110.03911.76
5.3.10.0060.04911.73
5.3.00.0090.05211.71
5.2.170.0060.0429.22
5.2.160.0100.0499.22
5.2.150.0050.0459.22
5.2.140.0020.0349.22
5.2.130.0040.0299.18
5.2.120.0050.0289.18
5.2.110.0020.0319.19
5.2.100.0030.0309.18
5.2.90.0080.0269.18
5.2.80.0060.0299.18
5.2.70.0060.0299.17
5.2.60.0050.0309.14
5.2.50.0060.0299.10
5.2.40.0080.0259.08
5.2.30.0070.0289.05
5.2.20.0020.0329.04
5.2.10.0050.0308.95
5.2.00.0040.0308.81
5.1.60.0040.0258.09
5.1.50.0040.0258.09
5.1.40.0030.0268.07
5.1.30.0060.0278.42
5.1.20.0050.0408.44
5.1.10.0090.0328.16
5.1.00.0060.0278.17
5.0.50.0040.0216.64
5.0.40.0030.0226.50
5.0.30.0050.0326.31
5.0.20.0050.0256.28
5.0.10.0040.0226.26
5.0.00.0040.0356.25
4.4.90.0040.0144.78
4.4.80.0040.0204.75
4.4.70.0050.0164.75
4.4.60.0020.0184.75
4.4.50.0020.0174.77
4.4.40.0020.0264.71
4.4.30.0030.0164.75
4.4.20.0030.0164.84
4.4.10.0040.0154.85
4.4.00.0050.0274.76
4.3.110.0040.0174.67
4.3.100.0070.0264.66
4.3.90.0030.0184.63
4.3.80.0060.0274.58
4.3.70.0030.0184.63
4.3.60.0060.0194.63
4.3.50.0050.0144.63
4.3.40.0020.0294.54
4.3.30.0040.0203.30
4.3.20.0060.0183.28
4.3.10.0040.0193.23
4.3.00.0000.0277.88

preferences:
41.11 ms | 401 KiB | 5 Q