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(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(); }, true); //Using an anonymous function $di->set('request2', 'Request', true); $request = $di->getShared('request2'); $request->answer = 5; var_dump($di->getShared('request2'));

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.40.0130.00318.96
8.3.30.0100.00319.17
8.3.20.0080.00020.29
8.3.10.0080.00021.73
8.3.00.0040.00419.38
8.2.170.0000.01518.92
8.2.160.0030.01022.96
8.2.150.0090.00924.18
8.2.140.0080.00024.66
8.2.130.0090.00026.16
8.2.120.0040.00421.93
8.2.110.0100.00020.39
8.2.100.0070.00718.10
8.2.90.0040.00418.28
8.2.80.0000.00917.97
8.2.70.0050.00317.63
8.2.60.0040.00417.80
8.2.50.0040.00418.07
8.2.40.0090.00020.01
8.2.30.0040.00418.16
8.2.20.0000.00717.77
8.2.10.0040.00418.09
8.2.00.0030.00517.95
8.1.270.0080.00022.02
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0000.00922.20
8.1.230.0060.00620.93
8.1.220.0040.00417.74
8.1.210.0050.00318.89
8.1.200.0060.00317.35
8.1.190.0080.00017.36
8.1.180.0080.00018.10
8.1.170.0050.00318.54
8.1.160.0040.00422.04
8.1.150.0080.00018.93
8.1.140.0000.00817.41
8.1.130.0080.00017.77
8.1.120.0030.00317.46
8.1.110.0030.00517.48
8.1.100.0040.00417.42
8.1.90.0030.00517.54
8.1.80.0000.00717.38
8.1.70.0000.00717.41
8.1.60.0060.00317.64
8.1.50.0030.00517.48
8.1.40.0060.00317.39
8.1.30.0040.00417.69
8.1.20.0040.00417.70
8.1.10.0050.00317.51
8.1.00.0000.00917.46
8.0.300.0050.00220.16
8.0.290.0060.00316.75
8.0.280.0050.00318.52
8.0.270.0040.00417.24
8.0.260.0070.00017.29
8.0.250.0000.00817.07
8.0.240.0000.00817.01
8.0.230.0000.00716.96
8.0.220.0030.00317.01
8.0.210.0030.00316.95
8.0.200.0030.00317.00
8.0.190.0000.00717.02
8.0.180.0040.00416.89
8.0.170.0000.00816.99
8.0.160.0030.00416.93
8.0.150.0070.00016.98
8.0.140.0070.00016.81
8.0.130.0060.00013.43
8.0.120.0040.00416.96
8.0.110.0000.00816.95
8.0.100.0070.00016.87
8.0.90.0040.00416.97
8.0.80.0100.01316.91
8.0.70.0070.00016.88
8.0.60.0000.00916.85
8.0.50.0000.00816.81
8.0.30.0130.00817.15
8.0.20.0160.00617.40
8.0.10.0040.00516.99
8.0.00.0080.01016.82
7.4.330.0060.00015.02
7.4.320.0000.00616.53
7.4.300.0030.00316.62
7.4.290.0020.00516.62
7.4.280.0040.00416.67
7.4.270.0070.00016.58
7.4.260.0070.00016.41
7.4.250.0040.00416.48
7.4.240.0020.00516.51
7.4.230.0050.00316.44
7.4.220.0060.01216.49
7.4.210.0100.00316.48
7.4.200.0030.00316.37
7.4.160.0160.00016.53
7.4.150.0060.01317.40
7.4.140.0090.00917.86
7.4.130.0080.00916.53
7.4.120.0050.01316.47
7.4.110.0090.00916.72
7.4.100.0040.01316.47
7.4.90.0060.01116.58
7.4.80.0030.01319.39
7.4.70.0100.00616.61
7.4.60.0100.00816.50
7.4.50.0100.00016.62
7.4.40.0000.01816.48
7.4.30.0090.00916.57
7.4.00.0000.01414.89
7.3.330.0050.00013.38
7.3.320.0000.00513.53
7.3.310.0040.00416.42
7.3.300.0040.00416.29
7.3.290.0100.00616.49
7.3.280.0070.01016.44
7.3.270.0070.01117.40
7.3.260.0090.00916.71
7.3.250.0080.00916.57
7.3.240.0090.01316.65
7.3.230.0060.01016.39
7.3.210.0100.00716.41
7.3.200.0130.01019.39
7.3.190.0160.00616.54
7.3.180.0130.00316.66
7.3.170.0040.01216.59
7.3.160.0070.01016.47
7.2.330.0130.00416.90
7.2.320.0030.01316.86
7.2.310.0070.01116.85
7.2.300.0060.01116.80
7.2.290.0120.00616.63
7.2.00.0110.00519.66
7.1.100.0070.00718.21
7.1.70.0060.00316.93
7.1.60.0030.02119.11
7.1.50.0070.01717.04
7.1.00.0030.07722.45
7.0.200.0030.00716.80
7.0.140.0100.06721.93
7.0.60.0070.08719.96
7.0.50.0030.07717.74
7.0.40.0130.07020.06
7.0.30.0400.06720.17
7.0.20.0270.07320.28
7.0.10.0130.05720.16
7.0.00.0170.07320.30
5.6.280.0000.07721.01
5.6.210.0030.04020.52
5.6.200.0100.08318.19
5.6.190.0030.04320.48
5.6.180.3900.04020.55
5.6.170.0300.08020.39
5.6.160.0100.04720.55
5.6.150.0130.07318.20
5.6.140.0070.04018.28
5.6.130.0030.04718.26
5.6.120.0170.07021.16
5.6.110.0230.07721.15
5.6.100.0170.07320.98
5.6.90.0030.05321.09
5.6.80.0100.03320.38
5.6.70.4430.03720.53
5.5.350.0070.07020.45
5.5.340.0100.07717.96
5.5.330.0130.07020.30
5.5.320.3470.04720.25
5.5.310.0230.03720.30
5.5.300.0070.03318.08
5.5.290.0130.03718.04
5.5.280.0130.07720.90
5.5.270.0130.04320.90
5.5.260.0070.08320.98
5.5.250.0030.08720.63
5.5.240.0270.07720.16
5.4.450.0170.04719.61
5.4.440.0100.06019.14
5.4.430.0630.04019.59
5.4.420.0670.00019.46
5.4.410.0670.00019.52
5.4.400.0630.00019.07
5.4.390.0630.00019.21
5.4.380.0630.00019.05
5.4.370.0630.00019.07
5.4.360.0630.00019.05
5.4.350.0800.00019.02
5.4.340.0050.03512.03
5.4.320.0040.03812.52
5.4.310.0120.03212.52
5.4.300.0050.03812.52
5.4.290.0030.04212.51
5.4.280.0040.03912.41
5.4.270.0070.03612.41
5.4.260.0060.03712.41
5.4.250.0040.03912.41
5.4.240.0070.03612.41
5.4.230.0070.03712.41
5.4.220.0060.03612.40
5.4.210.0040.03612.40
5.4.200.0050.03712.40
5.4.190.0070.03312.40
5.4.180.0040.03712.40
5.4.170.0080.03312.41
5.4.160.0100.03012.41
5.4.150.0040.03612.40
5.4.140.0030.03912.08
5.4.130.0060.03512.07
5.4.120.0060.03512.03
5.4.110.0050.03612.03
5.4.100.0040.03612.03
5.4.90.0030.04012.03
5.4.80.0020.04012.03
5.4.70.0070.03512.02
5.4.60.0100.03512.02
5.4.50.0090.03612.02
5.4.40.0030.03712.02
5.4.30.0070.03712.01
5.4.20.0070.04112.01
5.4.10.0070.03812.01
5.4.00.0050.03511.50
5.3.290.0060.03812.80
5.3.280.0090.03412.70
5.3.270.0110.03212.72
5.3.260.0050.03912.72
5.3.250.0050.03712.72
5.3.240.0090.03912.72
5.3.230.0080.03912.71
5.3.220.0060.04012.68
5.3.210.0050.03912.68
5.3.200.0080.03712.68
5.3.190.0080.04512.68
5.3.180.0060.03612.67
5.3.170.0070.03412.67
5.3.160.0040.03712.68
5.3.150.0100.03912.68
5.3.140.0070.03412.66
5.3.130.0090.04012.66
5.3.120.0050.03812.66
5.3.110.0070.04212.66
5.3.100.0070.03612.13
5.3.90.0090.03512.10
5.3.80.0090.03212.09
5.3.70.0060.04112.09
5.3.60.0070.03412.07
5.3.50.0040.03612.02
5.3.40.0040.03712.02
5.3.30.0080.03711.98
5.3.20.0040.03611.76
5.3.10.0110.02911.73
5.3.00.0080.03311.71
5.2.170.0040.0319.22
5.2.160.0040.0299.22
5.2.150.0010.0339.22
5.2.140.0030.0329.22
5.2.130.0070.0279.18
5.2.120.0050.0289.18
5.2.110.0030.0329.18
5.2.100.0080.0259.18
5.2.90.0040.0299.18
5.2.80.0040.0319.17
5.2.70.0050.0299.18
5.2.60.0050.0299.13
5.2.50.0050.0299.10
5.2.40.0050.0299.08
5.2.30.0040.0309.05
5.2.20.0050.0289.04
5.2.10.0060.0268.95
5.2.00.0060.0268.80
5.1.60.0050.0228.09
5.1.50.0030.0258.09
5.1.40.0030.0248.06
5.1.30.0040.0258.42
5.1.20.0040.0268.43
5.1.10.0040.0268.16
5.1.00.0020.0278.16
5.0.50.0030.0206.64
5.0.40.0020.0206.51
5.0.30.0030.0326.32
5.0.20.0010.0216.28
5.0.10.0040.0196.26
5.0.00.0030.0316.26
4.4.90.0050.0134.78
4.4.80.0030.0144.75
4.4.70.0040.0134.76
4.4.60.0020.0154.76
4.4.50.0030.0144.77
4.4.40.0030.0254.71
4.4.30.0040.0144.76
4.4.20.0040.0134.85
4.4.10.0030.0144.85
4.4.00.0020.0254.75
4.3.110.0020.0154.67
4.3.100.0030.0154.66
4.3.90.0040.0134.64
4.3.80.0010.0254.59
4.3.70.0040.0134.63
4.3.60.0020.0154.63
4.3.50.0030.0154.63
4.3.40.0020.0244.54
4.3.30.0020.0153.30
4.3.20.0010.0163.28
4.3.10.0000.0173.23
4.3.00.0030.0207.89

preferences:
81.16 ms | 400 KiB | 5 Q