3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { private $bar = 'baz'; public function getBar() { return $this->bar; } } // http://3v4l.org/pc6lo#v540 class ClassicLazyFoo extends Foo { private $initialized = false; public function getBar() { $this->init(); return parent::getBar(); } private function init() { if ($this->initialized) { return; } \Closure::bind(function() { $this->bar = 'Loaded from DB!'; }, $this, get_parent_class($this))->__invoke(); } } // look ma: no method overrides! class LazyPropertyLazyFoo extends Foo { public function __construct() { \Closure::bind(function() { unset($this->bar); }, $this, get_parent_class($this))->__invoke(); } // note that other accessors also need to be created for full functional completeness public function __get($name) { \Closure::bind(function() { $this->bar = 'Loaded from DB!'; }, $this, get_parent_class($this))->__invoke(); return \Closure::bind(function() use ($name) { return $this->$name; }, $this, get_parent_class($this))->__invoke(); } } var_dump((new ClassicLazyFoo())->getBar()); var_dump((new LazyPropertyLazyFoo())->getBar());

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.0140.00018.30
8.3.50.0290.00922.12
8.3.40.0060.01018.98
8.3.30.0070.01419.22
8.3.20.0040.00420.29
8.3.10.0030.00620.39
8.3.00.0080.00019.38
8.2.180.0040.01118.25
8.2.170.0040.01122.96
8.2.160.0110.00420.43
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0080.00022.24
8.2.110.0030.00622.20
8.2.100.0060.00617.72
8.2.90.0000.00819.13
8.2.80.0040.00417.97
8.2.70.0030.00617.50
8.2.60.0000.00817.80
8.2.50.0000.00818.07
8.2.40.0040.00418.03
8.2.30.0040.00419.15
8.2.20.0000.00817.70
8.2.10.0000.00818.13
8.2.00.0050.00317.56
8.1.280.0110.00725.92
8.1.270.0000.00822.13
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0140.00423.96
8.1.230.0090.00322.70
8.1.220.0040.00417.74
8.1.210.0040.00718.77
8.1.200.0060.00317.35
8.1.190.0040.00417.23
8.1.180.0040.00418.10
8.1.170.0030.00618.59
8.1.160.0000.00822.04
8.1.150.0030.00518.84
8.1.140.0040.00417.44
8.1.130.0070.00017.84
8.1.120.0050.00317.34
8.1.110.0000.00717.42
8.1.100.0000.00717.49
8.1.90.0020.00517.51
8.1.80.0090.00017.39
8.1.70.0000.00717.39
8.1.60.0040.00417.58
8.1.50.0050.00517.49
8.1.40.0040.00417.58
8.1.30.0040.00417.57
8.1.20.0000.00817.57
8.1.10.0040.00417.60
8.1.00.0070.00517.42
8.0.300.0040.00418.77
8.0.290.0000.00816.75
8.0.280.0030.00318.51
8.0.270.0070.00017.27
8.0.260.0000.00717.27
8.0.250.0070.00016.95
8.0.240.0070.00017.04
8.0.230.0030.00316.90
8.0.220.0020.00516.93
8.0.210.0030.00316.87
8.0.200.0000.00817.02
8.0.190.0090.00016.85
8.0.180.0040.00416.83
8.0.170.0000.00716.92
8.0.160.0000.00716.90
8.0.150.0040.00416.86
8.0.140.0040.00416.88
8.0.130.0030.00313.38
8.0.120.0040.00416.78
8.0.110.0000.00716.87
8.0.100.0000.00716.86
8.0.90.0040.00416.87
8.0.80.0110.00416.91
8.0.70.0000.00716.79
8.0.60.0000.00716.98
8.0.50.0020.00516.85
8.0.30.0130.00517.20
8.0.20.0070.01717.40
8.0.10.0050.00316.99
8.0.00.0170.00416.77
7.4.330.0000.00615.15
7.4.320.0060.00016.61
7.4.300.0030.00316.50
7.4.290.0000.01016.63
7.4.280.0040.00416.52
7.4.270.0000.00716.64
7.4.260.0000.00716.59
7.4.250.0000.00716.56
7.4.240.0040.00416.59
7.4.230.0030.00316.51
7.4.220.0130.00616.68
7.4.210.0060.00916.66
7.4.200.0050.00216.21
7.4.160.0060.00916.63
7.4.150.0120.00617.40
7.4.140.0070.01217.86
7.4.130.0060.01116.55
7.4.120.0080.01016.52
7.4.110.0070.01016.45
7.4.100.0030.01316.39
7.4.90.0060.01216.57
7.4.80.0100.00719.37
7.4.70.0060.01016.45
7.4.60.0100.00616.65
7.4.50.0000.00816.42
7.4.40.0070.01116.50
7.4.30.0060.01016.44
7.4.00.0000.01215.12
7.3.330.0000.00713.25
7.3.320.0000.00513.34
7.3.310.0000.00716.41
7.3.300.0030.00316.26
7.3.290.0090.00616.40
7.3.280.0110.00516.34
7.3.270.0070.01117.40
7.3.260.0100.01416.35
7.3.250.0160.00216.41
7.3.240.0070.00916.23
7.3.230.0060.01016.39
7.3.210.0120.00416.75
7.3.200.0150.00419.39
7.3.190.0030.01416.31
7.3.180.0060.01016.55
7.3.170.0100.00916.72
7.3.160.0140.00716.53
7.2.330.0040.01516.76
7.2.320.0130.00516.77
7.2.310.0190.00316.39
7.2.300.0150.00516.86
7.2.290.0060.01816.54
7.2.60.0090.00616.94
7.1.200.0080.00815.86
7.1.70.0030.00617.35
7.1.60.0160.00919.32
7.1.50.0110.01116.98
7.1.00.0030.07722.28
7.0.200.0060.00316.93
7.0.140.0030.07321.95
7.0.100.0470.08720.02
7.0.90.0400.08319.91
7.0.80.0430.07320.01
7.0.70.0530.06319.99
7.0.60.0070.04020.09
7.0.50.0070.05020.26
7.0.40.0070.06720.15
7.0.30.0030.08020.07
7.0.20.0170.06020.09
7.0.10.0100.08020.10
7.0.00.0130.05719.93
5.6.280.0030.07021.01
5.6.250.0030.06020.62
5.6.240.0000.08020.58
5.6.230.0130.06720.71
5.6.220.0000.07720.64
5.6.210.0000.08720.49
5.6.200.0100.07321.11
5.6.190.0170.07721.19
5.6.180.0030.05721.16
5.6.170.0030.09020.97
5.6.160.0030.06721.04
5.6.150.0030.05021.15
5.6.140.0070.05021.07
5.6.130.0070.04021.11
5.6.120.0070.04721.07
5.6.110.0030.05021.06
5.6.100.0070.06720.96
5.6.90.0000.04321.03
5.6.80.0100.04320.41
5.6.70.0070.03720.48
5.6.60.0030.08320.39
5.6.50.0030.04020.52
5.6.40.0030.07020.31
5.6.30.0000.05320.34
5.6.20.0100.03320.39
5.6.10.0030.06720.48
5.6.00.0100.04720.53
5.5.380.0030.06020.38
5.5.370.0130.07320.48
5.5.360.0070.07720.39
5.5.350.0070.08320.45
5.5.340.0030.08720.83
5.5.330.0100.08020.91
5.5.320.0030.05020.75
5.5.310.0100.08020.82
5.5.300.0070.07020.86
5.5.290.0070.04320.83
5.5.280.0030.04320.92
5.5.270.0100.03720.85
5.5.260.0170.03720.90
5.5.250.0000.04320.63
5.5.240.0070.03720.30
5.5.230.0030.06320.23
5.5.220.0070.05320.29
5.5.210.0030.04020.29
5.5.200.0070.08020.23
5.5.190.0070.07720.28
5.5.180.0130.07320.16
5.5.160.0030.03720.02
5.5.150.0000.04320.19
5.5.140.0000.06720.25
5.5.130.0030.06020.14
5.5.120.0030.04320.25
5.5.110.0000.04320.24
5.5.100.0070.07020.01
5.5.90.0070.06720.18
5.5.80.0000.04020.13
5.5.70.0030.04320.08
5.5.60.0030.03720.08
5.5.50.0000.05320.11
5.5.40.0000.04020.07
5.5.30.0030.03720.18
5.5.20.0070.07320.07
5.5.10.0000.04020.16
5.5.00.0030.04320.14
5.4.450.0030.04319.37
5.4.440.0000.04319.28
5.4.430.0070.03719.23
5.4.420.0100.03319.37
5.4.410.0030.03719.32
5.4.400.0030.05019.15
5.4.390.0030.06019.04
5.4.380.0130.06719.03
5.4.370.0130.07019.04
5.4.360.0130.07719.19
5.4.350.0100.07018.86
5.4.340.0000.05318.88
5.4.320.0030.04019.14
5.4.310.0030.05319.03
5.4.300.0070.03318.82
5.4.290.0030.03718.90
5.4.280.0100.03318.90
5.4.270.0070.03318.85
5.4.260.0000.04319.04
5.4.250.0000.04018.94
5.4.240.0070.05719.12
5.4.230.0100.03019.12
5.4.220.0000.04019.18
5.4.210.0000.04019.13
5.4.200.0030.04019.13
5.4.190.0070.04018.87
5.4.180.0030.03718.84
5.4.170.0000.04019.12
5.4.160.0000.06319.12
5.4.150.0000.04318.84
5.4.140.0030.03716.39
5.4.130.0070.07016.24
5.4.120.0070.05316.30
5.4.110.0030.08016.38
5.4.100.0170.06716.55
5.4.90.0030.07316.33
5.4.80.0070.07016.45
5.4.70.0030.07016.58
5.4.60.0070.07016.45
5.4.50.0030.07716.30
5.4.40.0130.06316.50
5.4.30.0170.06716.44
5.4.20.0100.07016.30
5.4.10.0030.07016.30
5.4.00.0000.07015.89
5.3.290.0030.04014.71
5.3.280.0030.03714.74
5.3.270.0030.05014.75
5.3.260.0000.04014.73
5.3.250.0030.03714.69
5.3.240.0030.05014.61
5.3.230.0130.03714.75
5.3.220.0000.04014.66
5.3.210.0030.06314.68
5.3.200.0030.08314.62
5.3.190.0130.05014.60
5.3.180.0130.06714.58
5.3.170.0030.07714.71
5.3.160.0070.07314.65
5.3.150.0030.07714.73
5.3.140.0070.06714.57
5.3.130.0000.05714.50
5.3.120.0070.04014.63
5.3.110.0030.07714.64
5.3.100.0030.07714.19
5.3.90.0030.05314.17
5.3.80.0070.06314.17
5.3.70.0030.04314.15
5.3.60.0070.07313.94
5.3.50.0100.07313.98
5.3.40.0070.08014.11
5.3.30.0070.07313.93
5.3.20.0030.04313.86
5.3.10.0030.07313.73
5.3.00.0100.06713.70
5.2.170.0030.04011.29
5.2.160.0070.06011.09
5.2.150.0000.04311.07
5.2.140.0030.06011.27
5.2.130.0030.06011.22
5.2.120.0070.05711.17
5.2.110.0030.05310.98
5.2.100.0030.06311.22
5.2.90.0070.03311.17
5.2.80.0030.05010.96
5.2.70.0030.05711.20
5.2.60.0070.05710.99
5.2.50.0130.03011.14
5.2.40.0030.06310.99
5.2.30.0000.04710.84
5.2.20.0100.06011.09
5.2.10.0000.06010.98
5.2.00.0000.05710.73
5.1.60.0030.05010.04
5.1.50.0070.04310.00
5.1.40.0200.02010.07
5.1.30.0100.04710.34
5.1.20.0070.05310.22
5.1.10.0100.04710.09
5.1.00.0070.0509.88
5.0.50.0070.0378.39
5.0.40.0030.0438.43
5.0.30.0070.0638.27
5.0.20.0130.0308.29
5.0.10.0000.0478.06
5.0.00.0030.0538.16
4.4.90.0030.0177.98
4.4.80.0000.0377.98
4.4.70.0070.0337.98
4.4.60.0000.0377.98
4.4.50.0070.0337.98
4.4.40.0030.0537.98
4.4.30.0030.0377.98
4.4.20.0070.0307.98
4.4.10.0070.0307.98
4.4.00.0030.0537.98
4.3.110.0070.0207.98
4.3.100.0000.0207.98
4.3.90.0070.0237.98
4.3.80.0000.0437.98
4.3.70.0030.0307.98
4.3.60.0030.0307.98
4.3.50.0030.0337.98
4.3.40.0000.0577.98
4.3.30.0000.0407.98
4.3.20.0130.0077.98
4.3.10.0030.0307.98
4.3.00.0000.0337.98

preferences:
40.94 ms | 401 KiB | 5 Q