3v4l.org

run code in 300+ PHP versions simultaneously
<?php class State { protected $foo; protected $bar; public function getFoo() { return $this->foo; } public function getBar() { return $this->bar; } public final function setFoo($foo) { $this->foo = $foo; } public final function setBar($bar) { $this->bar = $bar; } public final function transaction(callable $function) { $proxy = new StateProxy($this); if (call_user_func($function, $proxy)) { $proxy->commit(); } unset($proxy); } } class StateProxy extends State { protected $state; public function __construct(State $state) { $this->state = $state; } public function getFoo() { return parent::getFoo() ? : $this->state->getFoo(); } public function getBar() { return parent::getBar() ? : $this->state->getBar(); } public function commit() { $this->state->foo = $this->foo; $this->state->bar = $this->bar; } } $state = new State(); $state->setFoo('abc'); $state->setBar('123'); var_dump($state); // transaction succeeds, state changes $state->transaction(function(StateProxy $proxy) { $proxy->setFoo('def'); $proxy->setBar('456'); return true; }); var_dump($state); // transaction fails, state remains unchanged $state->transaction(function(StateProxy $proxy) { $proxy->setFoo('ghi'); $proxy->setBar('789'); return false; }); var_dump($state); $state = new State(); $state->setFoo('abc'); $state->setBar('123'); $state->transaction(function(StateProxy $proxy) { $proxy->transaction(function(StateProxy $proxy) { $proxy->transaction(function(StateProxy $proxy) { $proxy->transaction(function(StateProxy $proxy) { $proxy->setFoo('def'); $proxy->setBar('456'); return false; }); // this'll be the one to succeed $proxy->transaction(function(StateProxy $proxy) { $proxy->setFoo('ghi'); $proxy->setBar('789'); return true; }); return true; }); $proxy->transaction(function(StateProxy $proxy) { $proxy->setFoo('jkl'); $proxy->setBar('012'); return false; }); return true; }); return true; }); var_dump($state);

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.5.30.0120.01016.55
8.5.20.0120.00716.71
8.5.10.0110.00916.66
8.5.00.0140.00720.07
8.4.180.0150.00719.76
8.4.170.0160.00620.42
8.4.160.0090.01322.45
8.4.150.0080.00516.72
8.4.140.0120.00917.43
8.4.130.0070.00318.70
8.4.120.0110.00817.83
8.4.110.0130.00818.48
8.4.100.0040.00518.77
8.4.90.0140.00620.67
8.4.80.0110.00918.82
8.4.70.0090.01018.81
8.4.60.0050.00420.71
8.4.50.0140.00718.68
8.4.40.0100.01119.55
8.4.30.0100.01017.77
8.4.20.0070.01417.87
8.4.10.0090.00317.69
8.3.300.0160.00420.82
8.3.290.0120.01120.87
8.3.280.0110.00918.52
8.3.270.0090.01016.74
8.3.260.0110.00816.55
8.3.250.0130.00618.97
8.3.240.0140.00616.64
8.3.230.0130.00716.75
8.3.220.0120.00718.91
8.3.210.0100.00516.43
8.3.200.0050.00316.64
8.3.190.0100.01017.21
8.3.180.0070.00318.80
8.3.170.0100.01018.32
8.3.160.0060.01117.26
8.3.150.0070.01416.98
8.3.140.0080.00016.84
8.3.130.0090.00018.32
8.3.120.0000.00818.67
8.3.110.0030.00620.94
8.3.100.0140.00716.65
8.3.90.0050.00326.77
8.3.80.0060.00319.36
8.3.70.0060.01018.43
8.3.60.0070.00718.43
8.3.50.0080.00721.27
8.3.40.0150.00018.96
8.3.30.0120.00318.97
8.3.20.0000.00818.65
8.3.10.0080.00021.27
8.3.00.0040.00421.91
8.2.300.0030.00722.13
8.2.290.0110.00722.13
8.2.280.0090.01018.56
8.2.270.0080.01216.77
8.2.260.0090.00916.64
8.2.250.0150.00418.89
8.2.240.0090.00018.87
8.2.230.0050.00322.58
8.2.220.0070.00324.06
8.2.210.0030.00626.77
8.2.200.0030.00618.88
8.2.190.0110.00418.18
8.2.180.0130.00616.32
8.2.170.0120.00918.91
8.2.160.0100.00322.96
8.2.150.0070.00025.66
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0040.00421.11
8.2.110.0030.00620.27
8.2.100.0060.00617.72
8.2.90.0030.00519.08
8.2.80.0000.00817.97
8.2.70.0060.00317.63
8.2.60.0090.00018.16
8.2.50.0030.00518.07
8.2.40.0040.00418.03
8.2.30.0040.00421.29
8.2.20.0040.00417.68
8.2.10.0000.00717.58
8.2.00.0030.00617.69
8.1.340.0080.01419.93
8.1.330.0090.00722.04
8.1.320.0070.01215.95
8.1.310.0080.01116.21
8.1.300.0090.00920.12
8.1.290.0090.00030.84
8.1.280.0110.00425.92
8.1.270.0140.00023.99
8.1.260.0050.00326.35
8.1.250.0080.00028.09
8.1.240.0030.00622.47
8.1.230.0090.00320.83
8.1.220.0040.00418.77
8.1.210.0030.00518.87
8.1.200.0070.00317.35
8.1.190.0040.00417.52
8.1.180.0000.00818.10
8.1.170.0000.00818.66
8.1.160.0040.00418.96
8.1.150.0070.00018.55
8.1.140.0060.00317.48
8.1.130.0050.00217.86
8.1.120.0000.00717.43
8.1.110.0020.00517.53
8.1.100.0050.00317.44
8.1.90.0050.00317.38
8.1.80.0040.00417.39
8.1.70.0000.00717.35
8.1.60.0040.00417.57
8.1.50.0040.00417.50
8.1.40.0000.00817.52
8.1.30.0080.00017.57
8.1.20.0030.00517.55
8.1.10.0060.00317.60
8.1.00.0030.00917.40
8.0.300.0040.00419.91
8.0.290.0040.00417.05
8.0.280.0070.00018.35
8.0.270.0020.00517.18
8.0.260.0050.00316.73
8.0.250.0000.00716.92
8.0.240.0040.00417.07
8.0.230.0070.00016.95
8.0.220.0040.00416.83
8.0.210.0000.00716.92
8.0.200.0060.00016.93
8.0.190.0040.00417.07
8.0.180.0030.00516.88
8.0.170.0000.00816.98
8.0.160.0040.00416.96
8.0.150.0040.00416.93
8.0.140.0040.00416.93
8.0.130.0000.00613.43
8.0.120.0040.00416.78
8.0.110.0040.00416.88
8.0.100.0000.00716.89
8.0.90.0070.00016.85
8.0.80.0120.00316.97
8.0.70.0040.00416.95
8.0.60.0040.00417.03
8.0.50.0000.00716.89
8.0.30.0100.01016.82
8.0.20.0130.01217.43
8.0.10.0040.00417.07
8.0.00.0090.01316.65
7.4.330.0050.00014.89
7.4.320.0000.00616.59
7.4.300.0040.00416.54
7.4.290.0000.00716.58
7.4.280.0030.00316.41
7.4.270.0030.00316.55
7.4.260.0030.00313.32
7.4.250.0040.00416.49
7.4.240.0020.00516.60
7.4.230.0000.00716.65
7.4.220.0090.01816.69
7.4.210.0060.00916.53
7.4.200.0070.00016.54
7.4.190.0040.00416.49
7.4.160.0040.01216.50
7.4.150.0060.01317.40
7.4.140.0100.00917.86
7.4.130.0090.01516.60
7.4.120.0100.01016.54
7.4.110.0100.01016.45
7.4.100.0120.00616.54
7.4.90.0070.01116.48
7.4.80.0170.00019.39
7.4.70.0070.01116.46
7.4.60.0070.01016.50
7.4.50.0040.00416.41
7.4.40.0060.00622.77
7.4.30.0160.00716.68
7.4.00.0080.00915.21
7.3.330.0030.00313.20
7.3.320.0050.00013.32
7.3.310.0040.00416.20
7.3.300.0070.00016.37
7.3.290.0090.00316.34
7.3.280.0100.00816.35
7.3.270.0140.00417.40
7.3.260.0100.01218.24
7.3.250.0090.01116.42
7.3.240.0070.01116.40
7.3.230.0060.01216.53
7.3.210.0080.01216.41
7.3.200.0110.00819.39
7.3.190.0170.00016.50
7.3.180.0160.00316.54
7.3.170.0100.00616.63
7.3.160.0160.00616.44
7.3.120.0070.01014.92
7.2.330.0040.01516.47
7.2.320.0110.00816.79
7.2.310.0030.01616.84
7.2.300.0110.00616.75
7.2.290.0070.01016.74
7.2.60.0100.00316.96
7.1.200.0000.01115.83
7.1.70.0030.00617.29
7.1.60.0100.01419.40
7.1.50.0060.01817.04
7.1.00.0000.03722.37
7.0.200.0030.01016.86
7.0.140.0030.07022.12
7.0.110.0330.08020.02
7.0.100.0030.06720.01
7.0.90.0030.10019.99
7.0.80.0100.04720.08
7.0.70.0100.07020.05
7.0.60.0030.04320.04
7.0.50.0470.03720.11
7.0.40.0000.05019.82
7.0.30.0070.04019.65
7.0.20.0030.04019.61
7.0.10.0030.07319.72
7.0.00.0000.05019.70
5.6.280.0070.06321.14
5.6.260.0000.04720.75
5.6.250.0000.04020.94
5.6.240.0070.03720.70
5.6.230.0000.04720.72
5.6.220.0100.03020.50
5.6.210.0030.04020.45
5.6.200.0100.06720.69
5.6.190.0030.05720.69
5.6.180.0030.04020.61
5.6.170.0130.06020.70
5.6.160.0030.05720.75
5.6.150.0070.07020.90
5.6.140.0070.04020.70
5.6.130.0100.03720.70
5.6.120.0000.05020.61
5.6.110.0070.06020.56
5.6.100.0030.06720.71
5.6.90.0070.03720.68
5.6.80.0130.07319.98
5.6.70.0000.08719.96
5.6.60.0070.08019.97
5.6.50.0030.08020.07
5.6.40.0170.03320.11
5.6.30.0070.07019.96
5.6.20.0130.05019.99
5.6.10.0070.05020.01
5.6.00.0030.06720.11
5.5.380.0000.04317.64
5.5.370.0130.06017.72
5.5.360.0070.05717.50
5.5.350.0000.03717.66
5.5.340.0100.07017.99
5.5.330.0070.07018.23
5.5.320.0000.04317.93
5.5.310.0000.05718.23
5.5.300.0100.05717.95
5.5.290.0000.04017.93
5.5.280.0030.04318.22
5.5.270.0030.05318.25
5.5.260.0130.05018.25
5.5.250.0070.08317.95
5.5.240.0200.06317.49
5.5.230.0030.03717.53
5.5.220.0070.04717.43
5.5.210.0000.04017.64
5.5.200.0070.03017.32
5.5.190.0000.05017.21
5.5.180.0200.06317.61
5.5.160.0070.07317.31
5.5.150.0070.07717.44
5.5.140.0100.06017.59
5.5.130.0000.08317.61
5.5.120.0200.05317.48
5.5.110.0030.04317.48
5.5.100.0070.07317.37
5.5.90.0030.06017.41
5.5.80.0100.06017.19
5.5.70.0030.07317.38
5.5.60.0070.06717.46
5.5.50.0030.04317.20
5.5.40.0000.04317.47
5.5.30.0030.08017.23
5.5.20.0000.08317.19
5.5.10.0000.04317.29
5.5.00.0130.07717.46
5.4.450.0100.04019.48
5.4.440.0070.03719.39
5.4.430.0000.07319.66
5.4.420.0070.05019.33
5.4.410.0070.05019.14
5.4.400.0030.04319.18
5.4.390.0030.07019.02
5.4.380.0030.07319.24
5.4.370.0030.04319.01
5.4.360.0030.06719.18
5.4.350.0070.06019.23
5.4.340.0070.03319.03
5.4.320.0030.04019.34
5.4.310.0000.03719.00
5.4.300.0000.04319.00
5.4.290.0030.05319.34
5.4.280.0100.06019.24
5.4.270.0000.03719.14
5.4.260.0000.07019.09
5.4.250.0070.04019.22
5.4.240.0100.06019.32
5.4.230.0070.07719.08
5.4.220.0100.04019.02
5.4.210.0100.06319.05
5.4.200.0030.06718.98
5.4.190.0070.06719.16
5.4.180.0200.05319.18
5.4.170.0230.05019.00
5.4.160.0070.08019.21
5.4.150.0030.04319.00
5.4.140.0130.06016.52
5.4.130.0070.04016.43
5.4.120.0100.05316.43
5.4.110.0000.07316.31
5.4.100.0130.07716.60
5.4.90.0070.03316.64
5.4.80.0100.04316.69
5.4.70.0070.03316.59
5.4.60.0030.03716.53
5.4.50.0130.05316.59
5.4.40.0030.06716.61
5.4.30.0170.03016.57
5.4.20.0030.07316.61
5.4.10.0070.03316.57
5.4.00.0000.07715.86
5.3.290.0030.06714.96
5.3.280.0030.04314.67
5.3.270.0070.05714.68
5.3.260.0100.07014.73
5.3.250.0000.07014.66
5.3.240.0000.07314.66
5.3.230.0100.06314.60
5.3.220.0030.06314.75
5.3.210.0030.04014.84
5.3.200.0100.04014.63
5.3.190.0130.04314.70
5.3.180.0100.06014.47
5.3.170.0030.04014.60
5.3.160.0000.04014.61
5.3.150.0200.06014.75
5.3.140.0030.04314.74
5.3.130.0000.07714.61
5.3.120.0070.04314.55
5.3.110.0030.10314.45
5.3.100.0070.07714.05
5.3.90.0030.05014.05
5.3.80.0000.06714.07
5.3.70.0100.03314.20
5.3.60.0100.07313.89
5.3.50.0130.05014.03
5.3.40.0070.05013.97
5.3.30.0070.04713.96
5.3.20.0030.06713.80
5.3.10.0130.03713.73
5.3.00.0030.06713.68
5.2.170.0070.02711.95
5.2.160.0000.03311.95
5.2.150.0100.05711.95
5.2.140.0030.06711.95
5.2.130.0070.06011.95
5.2.120.0070.05711.95
5.2.110.0030.03011.95
5.2.100.0100.02711.95
5.2.90.0000.06311.95
5.2.80.0070.05011.95
5.2.70.0000.04011.95
5.2.60.0030.04711.95
5.2.50.0000.03011.95
5.2.40.0030.06711.95
5.2.30.0030.03711.95
5.2.20.0030.03311.95
5.2.10.0030.03011.95
5.2.00.0030.06011.95
5.1.60.0030.02711.95
5.1.50.0070.04711.95
5.1.40.0030.03011.95
5.1.30.0000.03711.95
5.1.20.0000.04011.95
5.1.10.0000.04311.95
5.1.00.0070.02711.95
5.0.50.0070.01711.95
5.0.40.0070.03711.95
5.0.30.0000.04011.95
5.0.20.0000.03011.95
5.0.10.0000.04011.95
5.0.00.0030.05711.95
4.4.90.0030.02711.95
4.4.80.0000.01711.95
4.4.70.0000.03011.95
4.4.60.0070.02011.95
4.4.50.0000.02711.95
4.4.40.0000.03311.95
4.4.30.0030.02311.95
4.4.20.0030.01711.95
4.4.10.0000.01711.95
4.4.00.0000.02311.95
4.3.110.0070.01311.95
4.3.100.0000.03711.95
4.3.90.0000.01711.95
4.3.80.0000.02711.95
4.3.70.0000.01711.95
4.3.60.0030.01311.95
4.3.50.0070.02311.95
4.3.40.0030.02311.95
4.3.30.0000.01711.95
4.3.20.0000.02011.95
4.3.10.0000.02311.95
4.3.00.0000.01311.95

preferences:
50.44 ms | 2337 KiB | 5 Q