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(); }, true); //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.0040.01118.15
8.3.50.0130.00821.25
8.3.40.0120.00418.59
8.3.30.0110.00319.22
8.3.20.0070.00020.34
8.3.10.0000.00821.85
8.3.00.0060.00319.15
8.2.180.0080.00816.38
8.2.170.0160.00622.96
8.2.160.0090.00618.93
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0050.00326.16
8.2.120.0040.00418.86
8.2.110.0090.00020.35
8.2.100.0090.00317.91
8.2.90.0030.00618.28
8.2.80.0030.00517.97
8.2.70.0030.00517.63
8.2.60.0040.00417.93
8.2.50.0040.00418.07
8.2.40.0080.00019.66
8.2.30.0040.00418.19
8.2.20.0040.00417.82
8.2.10.0040.00418.17
8.2.00.0090.00017.72
8.1.280.0170.00025.92
8.1.270.0040.00422.36
8.1.260.0000.00826.35
8.1.250.0080.00028.09
8.1.240.0090.00022.22
8.1.230.0060.00620.96
8.1.220.0080.00017.74
8.1.210.0080.00018.97
8.1.200.0070.00317.48
8.1.190.0040.00417.47
8.1.180.0050.00318.10
8.1.170.0040.00418.71
8.1.160.0050.00222.07
8.1.150.0040.00418.99
8.1.140.0040.00417.52
8.1.130.0080.00017.76
8.1.120.0050.00317.52
8.1.110.0060.00317.53
8.1.100.0020.00517.42
8.1.90.0050.00317.39
8.1.80.0000.00717.55
8.1.70.0000.00717.48
8.1.60.0060.00317.55
8.1.50.0000.00917.53
8.1.40.0040.00417.57
8.1.30.0000.00917.64
8.1.20.0050.00317.77
8.1.10.0040.00417.59
8.1.00.0040.00417.57
8.0.300.0030.00520.25
8.0.290.0080.00016.75
8.0.280.0040.00318.49
8.0.270.0070.00017.23
8.0.260.0000.00617.35
8.0.250.0070.00016.95
8.0.240.0040.00416.98
8.0.230.0030.00316.97
8.0.220.0030.00316.82
8.0.210.0000.00816.84
8.0.200.0000.00817.02
8.0.190.0070.00016.94
8.0.180.0040.00417.03
8.0.170.0040.00416.86
8.0.160.0040.00416.84
8.0.150.0000.00716.89
8.0.140.0000.00716.91
8.0.130.0000.00613.32
8.0.120.0000.00716.96
8.0.110.0050.00316.89
8.0.100.0040.00416.91
8.0.90.0040.00416.98
8.0.80.0150.00616.89
8.0.70.0000.00716.80
8.0.60.0000.00816.82
8.0.50.0000.00716.89
8.0.30.0150.00517.12
8.0.20.0090.01117.40
8.0.10.0040.00417.12
8.0.00.0110.00716.68
7.4.330.0000.00515.20
7.4.320.0060.00016.56
7.4.300.0000.00616.54
7.4.290.0030.00316.56
7.4.280.0070.00016.60
7.4.270.0040.00416.58
7.4.260.0030.00616.55
7.4.250.0000.00716.66
7.4.240.0020.00516.52
7.4.230.0030.00316.44
7.4.220.0120.00616.63
7.4.210.0070.00616.64
7.4.200.0000.00716.72
7.4.160.0080.00816.37
7.4.150.0120.00617.40
7.4.140.0130.00617.86
7.4.130.0090.00916.53
7.4.120.0130.00516.66
7.4.110.0110.00716.56
7.4.100.0040.01316.45
7.4.90.0070.01016.58
7.4.80.0060.01219.39
7.4.70.0090.00816.43
7.4.60.0000.01716.53
7.4.50.0040.00416.63
7.4.40.0150.00416.55
7.4.30.0130.00516.46
7.4.00.0090.00915.13
7.3.330.0050.00013.28
7.3.320.0000.00513.40
7.3.310.0000.00716.45
7.3.300.0070.00016.38
7.3.290.0090.00916.48
7.3.280.0090.01116.36
7.3.270.0170.00017.40
7.3.260.0130.01016.38
7.3.250.0100.00816.67
7.3.240.0130.00516.48
7.3.230.0030.01316.46
7.3.210.0070.01116.63
7.3.200.0050.01119.39
7.3.190.0070.01016.56
7.3.180.0100.00616.74
7.3.170.0100.01016.47
7.3.160.0070.01116.48
7.2.330.0110.00816.70
7.2.320.0100.00716.84
7.2.310.0060.01816.79
7.2.300.0030.01516.71
7.2.290.0130.00916.57
7.2.60.0090.00317.13
7.2.00.0060.01019.44
7.1.200.0000.01015.77
7.1.100.0060.00618.38
7.1.70.0000.00817.09
7.1.60.0030.02119.11
7.1.50.0160.00617.12
7.1.00.0070.07322.31
7.0.200.0060.00316.94
7.0.140.0130.06321.96
7.0.60.0030.05020.10
7.0.50.0170.07317.88
7.0.40.0070.04019.96
7.0.30.0700.05720.07
7.0.20.0170.04320.25
7.0.10.0130.04720.23
7.0.00.0100.08720.20
5.6.280.0130.06320.93
5.6.210.0070.07720.54
5.6.200.0200.07318.18
5.6.190.0030.06320.47
5.6.180.3500.04020.61
5.6.170.0370.07020.55
5.6.160.0070.04320.55
5.6.150.0100.04718.24
5.6.140.0070.05318.18
5.6.130.0070.03718.16
5.6.120.0030.04721.01
5.6.110.0070.07321.06
5.6.100.0030.08021.04
5.6.90.0000.04720.98
5.6.80.0070.05020.30
5.6.70.3270.03320.49
5.5.350.0270.07320.42
5.5.340.0070.05017.96
5.5.330.0170.03020.43
5.5.320.0370.06720.25
5.5.310.0130.04320.36
5.5.300.0070.08018.09
5.5.290.0030.08317.99
5.5.280.0030.04720.84
5.5.270.0130.07720.88
5.5.260.0100.08320.97
5.5.250.0100.07320.77
5.5.240.0130.07320.21
5.4.450.1100.03319.17
5.4.440.0570.05319.45
5.4.430.0530.06019.27
5.4.420.0670.00019.50
5.4.410.0830.00019.36
5.4.400.0630.00019.02
5.4.390.0630.00019.03
5.4.380.0630.00019.03
5.4.370.0600.00019.02
5.4.360.0570.00019.16
5.4.350.0670.00019.03
5.4.340.0070.03612.03
5.4.320.0050.03812.52
5.4.310.0070.03812.51
5.4.300.0030.03912.52
5.4.290.0090.04412.51
5.4.280.0080.04012.41
5.4.270.0070.05012.41
5.4.260.0070.04812.41
5.4.250.0070.03612.41
5.4.240.0050.03712.41
5.4.230.0060.03812.40
5.4.220.0070.03712.40
5.4.210.0120.03512.40
5.4.200.0050.03912.41
5.4.190.0050.03712.40
5.4.180.0070.03812.39
5.4.170.0080.03612.41
5.4.160.0070.03412.41
5.4.150.0040.03912.40
5.4.140.0080.03512.08
5.4.130.0040.03812.07
5.4.120.0130.03812.03
5.4.110.0090.04712.03
5.4.100.0120.04212.03
5.4.90.0090.04112.03
5.4.80.0070.05412.03
5.4.70.0110.04212.02
5.4.60.0080.04012.02
5.4.50.0090.03412.02
5.4.40.0030.03912.01
5.4.30.0040.03712.01
5.4.20.0080.03412.01
5.4.10.0050.03812.01
5.4.00.0080.04111.50
5.3.290.0050.04012.80
5.3.280.0070.04412.71
5.3.270.0040.04212.72
5.3.260.0060.03812.72
5.3.250.0090.03512.71
5.3.240.0100.03412.72
5.3.230.0050.03812.70
5.3.220.0070.03612.68
5.3.210.0100.04012.68
5.3.200.0070.04212.68
5.3.190.0040.03912.68
5.3.180.0050.03712.68
5.3.170.0060.03612.67
5.3.160.0060.04712.67
5.3.150.0060.05012.67
5.3.140.0080.04012.66
5.3.130.0060.04012.66
5.3.120.0070.03712.66
5.3.110.0040.04512.66
5.3.100.0060.04912.13
5.3.90.0040.04512.10
5.3.80.0090.03612.09
5.3.70.0120.03912.09
5.3.60.0050.04612.08
5.3.50.0060.03712.03
5.3.40.0060.03612.02
5.3.30.0040.03711.98
5.3.20.0070.04911.76
5.3.10.0080.03111.73
5.3.00.0090.03311.72
5.2.170.0050.0359.23
5.2.160.0070.0329.23
5.2.150.0060.0329.22
5.2.140.0010.0349.22
5.2.130.0050.0299.18
5.2.120.0050.0299.18
5.2.110.0040.0299.18
5.2.100.0020.0309.18
5.2.90.0040.0299.18
5.2.80.0030.0319.17
5.2.70.0060.0289.17
5.2.60.0020.0329.13
5.2.50.0060.0299.10
5.2.40.0020.0319.08
5.2.30.0040.0349.05
5.2.20.0060.0339.04
5.2.10.0040.0318.94
5.2.00.0040.0318.80
5.1.60.0050.0238.09
5.1.50.0040.0248.09
5.1.40.0050.0278.07
5.1.30.0090.0218.42
5.1.20.0050.0308.44
5.1.10.0070.0288.17
5.1.00.0040.0258.17
5.0.50.0040.0206.64
5.0.40.0030.0226.51
5.0.30.0020.0336.31
5.0.20.0040.0186.28
5.0.10.0040.0196.26
5.0.00.0050.0286.26
4.4.90.0040.0134.78
4.4.80.0030.0154.76
4.4.70.0050.0144.76
4.4.60.0050.0144.76
4.4.50.0010.0174.77
4.4.40.0020.0294.71
4.4.30.0020.0164.76
4.4.20.0040.0164.84
4.4.10.0020.0194.85
4.4.00.0040.0274.76
4.3.110.0040.0154.67
4.3.100.0030.0164.67
4.3.90.0030.0144.64
4.3.80.0030.0244.58
4.3.70.0020.0154.63
4.3.60.0020.0144.62
4.3.50.0040.0144.63
4.3.40.0030.0234.54
4.3.30.0010.0173.30
4.3.20.0010.0223.28
4.3.10.0020.0153.24
4.3.00.0300.01312.38

preferences:
43.87 ms | 400 KiB | 5 Q