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($object) { $object->bar = 'Loaded from DB!'; }, null, get_parent_class($this))->__invoke($this); var_dump(get_parent_class($this)); return $this->$name; } } 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.70.0160.00316.88
8.3.60.0140.00318.20
8.3.50.0210.00822.18
8.3.40.0120.00418.96
8.3.30.0030.01519.07
8.3.20.0080.00020.21
8.3.10.0040.00420.51
8.3.00.0040.00419.25
8.2.180.0070.00716.75
8.2.170.0140.00722.96
8.2.160.0100.00320.22
8.2.150.0100.00724.18
8.2.140.0040.00424.66
8.2.130.0060.00326.16
8.2.120.0040.00422.03
8.2.110.0030.00620.95
8.2.100.0030.00917.75
8.2.90.0050.00319.22
8.2.80.0000.00817.97
8.2.70.0060.00317.61
8.2.60.0010.00917.93
8.2.50.0090.00018.07
8.2.40.0000.00818.09
8.2.30.0040.00419.15
8.2.20.0040.00417.59
8.2.10.0070.00018.14
8.2.00.0000.00817.71
8.1.280.0070.01025.92
8.1.270.0080.00023.79
8.1.260.0070.00026.35
8.1.250.0050.00328.09
8.1.240.0000.00919.09
8.1.230.0000.01117.42
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0050.00517.35
8.1.190.0030.00617.23
8.1.180.0040.00418.10
8.1.170.0040.00418.63
8.1.160.0050.00222.03
8.1.150.0080.00018.97
8.1.140.0040.00417.35
8.1.130.0030.00517.46
8.1.120.0050.00317.41
8.1.110.0040.00417.37
8.1.100.0030.00517.36
8.1.90.0000.00717.43
8.1.80.0090.00017.52
8.1.70.0030.00317.43
8.1.60.0030.00617.62
8.1.50.0070.00417.47
8.1.40.0040.00417.52
8.1.30.0040.00417.53
8.1.20.0060.00317.55
8.1.10.0030.00617.50
8.1.00.0030.00717.60
8.0.300.0000.00718.77
8.0.290.0070.00016.88
8.0.280.0030.00418.49
8.0.270.0000.00817.26
8.0.260.0030.00316.81
8.0.250.0000.00716.96
8.0.240.0050.00217.02
8.0.230.0030.00316.99
8.0.220.0000.00716.99
8.0.210.0000.00716.98
8.0.200.0000.00717.00
8.0.190.0050.00316.99
8.0.180.0040.00417.02
8.0.170.0070.00017.04
8.0.160.0070.00017.05
8.0.150.0040.00416.89
8.0.140.0070.00016.83
8.0.130.0000.00513.39
8.0.120.0000.00716.93
8.0.110.0050.00316.98
8.0.100.0000.00917.03
8.0.90.0040.00417.07
8.0.80.0040.01216.96
8.0.70.0040.00417.04
8.0.60.0070.00017.03
8.0.50.0000.00717.00
8.0.30.0100.01017.14
8.0.20.0140.00617.40
8.0.10.0040.00416.91
8.0.00.0130.00816.79
7.4.330.0000.00615.08
7.4.320.0040.00416.52
7.4.300.0030.00316.43
7.4.290.0050.00316.53
7.4.280.0040.00416.50
7.4.270.0040.00416.53
7.4.260.0000.00716.52
7.4.250.0040.00316.43
7.4.240.0040.00416.50
7.4.230.0000.00716.43
7.4.220.0130.01016.67
7.4.210.0080.00516.59
7.4.200.0050.00216.55
7.4.160.0130.01016.45
7.4.150.0150.00617.40
7.4.140.0110.00717.86
7.4.130.0030.01616.65
7.4.120.0050.01416.56
7.4.110.0160.00616.49
7.4.100.0100.00716.45
7.4.90.0090.00916.47
7.4.80.0090.00919.37
7.4.70.0060.01216.57
7.4.60.0180.00616.64
7.4.50.0000.00816.26
7.4.40.0120.00616.55
7.4.30.0090.00616.30
7.4.00.0000.01714.80
7.3.330.0030.00313.45
7.3.320.0050.00013.48
7.3.310.0000.00716.35
7.3.300.0000.00716.36
7.3.290.0120.00716.46
7.3.280.0090.00916.45
7.3.270.0070.02117.40
7.3.260.0120.01216.55
7.3.250.0080.01116.67
7.3.240.0130.00316.46
7.3.230.0040.01416.40
7.3.210.0080.00816.58
7.3.200.0130.00719.39
7.3.190.0060.01216.58
7.3.180.0070.01316.57
7.3.170.0120.01216.44
7.3.160.0130.00916.41
7.3.10.0070.00716.71
7.3.00.0080.00416.59
7.2.330.0040.01416.73
7.2.320.0090.00916.70
7.2.310.0090.00916.46
7.2.300.0110.00716.74
7.2.290.0140.00816.80
7.2.130.0110.00016.77
7.2.120.0070.00716.79
7.2.110.0030.00816.72
7.2.100.0060.00917.03
7.2.90.0060.00617.00
7.2.80.0030.00716.91
7.2.70.0110.00016.77
7.2.60.0050.00916.74
7.2.50.0190.00516.72
7.2.40.0100.00017.12
7.2.30.0030.01016.90
7.2.20.0000.01416.72
7.2.10.0070.00417.00
7.2.00.0090.00616.84
7.1.250.0000.01015.88
7.1.200.0030.00915.82
7.1.70.0030.01017.18
7.1.60.0140.01119.32
7.1.50.0190.00317.05
7.1.00.0000.08022.54
7.0.200.0040.00416.80
7.0.140.0070.07321.95
7.0.60.0100.03320.04
7.0.50.0070.05017.98
7.0.40.0000.04720.30
7.0.30.0500.05020.13
7.0.20.0170.04320.26
7.0.10.0070.05720.12
7.0.00.0200.07320.37
5.6.280.0030.07321.10
5.6.210.0100.05720.77
5.6.200.0100.03318.29
5.6.190.0000.05020.48
5.6.180.0530.07020.60
5.6.170.0500.06720.45
5.6.160.0170.05020.48
5.6.150.0070.06718.19
5.6.140.0100.05718.15
5.6.130.0130.08318.13
5.6.120.0070.04720.92
5.6.110.0100.08021.13
5.6.100.0100.08321.03
5.6.90.0130.07721.13
5.6.80.0070.03720.40
5.5.350.0170.08720.54
5.5.340.0100.04318.05
5.5.330.0130.03320.33
5.5.320.0330.08320.51
5.5.310.0200.07720.37
5.5.300.0000.04017.98
5.5.290.0030.06718.04
5.5.280.0100.08020.91
5.5.270.0070.04020.97
5.5.260.0100.08320.79
5.5.250.0130.06720.61
5.5.240.0100.08320.30
5.4.450.0830.05719.48
5.4.440.1100.04719.63
5.4.430.0700.06019.69
5.4.420.0670.00019.38
5.4.410.0870.00019.45
5.4.400.0630.00019.34
5.4.390.0630.00019.27
5.4.380.0570.05318.77
5.4.370.0370.04718.58
5.4.360.0400.06718.55
5.4.350.0430.07318.58
5.4.340.0200.06018.80
5.4.320.0080.03812.52
5.4.310.0050.05112.52
5.4.300.0080.03412.52
5.4.290.0090.05012.52
5.4.280.0100.04912.42
5.4.270.0080.04812.42
5.4.260.0080.05212.42
5.4.250.0090.04012.41
5.4.240.0080.04512.42
5.4.230.0040.05412.41
5.4.220.0090.04912.41
5.4.210.0080.04912.41
5.4.200.0060.05412.41
5.4.190.0070.04112.41
5.4.180.0060.03612.41
5.4.170.0110.03012.41
5.4.160.0090.03312.41
5.4.150.0060.04512.40
5.4.140.0120.04512.09
5.4.130.0050.03912.08
5.4.120.0070.03512.04
5.4.110.0090.03212.04
5.4.100.0090.03312.04
5.4.90.0050.03912.04
5.4.80.0040.03812.03
5.4.70.0040.03612.03
5.4.60.0070.03712.03
5.4.50.0130.02912.03
5.4.40.0100.03112.02
5.4.30.0060.03712.02
5.4.20.0070.03712.02
5.4.10.0060.03712.00
5.4.00.0070.03611.49
5.3.290.0060.04212.80
5.3.280.0060.03812.71
5.3.270.0060.04612.73
5.3.260.0050.04112.72
5.3.250.0060.03812.73
5.3.240.0060.03812.73
5.3.230.0070.03812.72
5.3.220.0100.03412.69
5.3.210.0070.04012.69
5.3.200.0050.03912.69
5.3.190.0080.03512.69
5.3.180.0060.03712.68
5.3.170.0060.03712.68
5.3.160.0060.03612.68
5.3.150.0040.03812.68
5.3.140.0120.03712.67
5.3.130.0070.03912.67
5.3.120.0070.03812.67
5.3.110.0080.03912.67
5.3.100.0030.04112.16
5.3.90.0050.03912.14
5.3.80.0040.03912.13
5.3.70.0080.04612.14
5.3.60.0060.03612.12
5.3.50.0060.03812.06
5.3.40.0050.03812.06
5.3.30.0060.03512.03
5.3.20.0080.03311.80
5.3.10.0050.03511.77
5.3.00.0040.03811.76
5.2.170.0040.0319.23
5.2.160.0070.0279.23
5.2.150.0080.0279.23
5.2.140.0060.0299.23
5.2.130.0050.0289.18
5.2.120.0050.0279.19
5.2.110.0030.0339.19
5.2.100.0060.0289.18
5.2.90.0000.0369.19
5.2.80.0040.0329.18
5.2.70.0070.0299.18
5.2.60.0040.0319.14
5.2.50.0030.0369.11
5.2.40.0060.0289.08
5.2.30.0080.0289.05
5.2.20.0060.0349.05
5.2.10.0020.0308.95
5.2.00.0040.0328.82
5.1.60.0050.0238.10
5.1.50.0020.0278.10
5.1.40.0040.0258.07
5.1.30.0040.0288.42
5.1.20.0060.0258.45
5.1.10.0060.0268.17
5.1.00.0050.0258.17
5.0.50.0020.0236.65
5.0.40.0030.0206.51
5.0.30.0020.0326.32
5.0.20.0010.0216.29
5.0.10.0030.0216.27
5.0.00.0060.0286.26
4.4.90.0020.0164.78
4.4.80.0030.0154.75
4.4.70.0050.0154.76
4.4.60.0010.0174.75
4.4.50.0010.0174.77
4.4.40.0020.0264.71
4.4.30.0010.0184.76
4.4.20.0020.0164.85
4.4.10.0030.0154.85
4.4.00.0020.0274.76
4.3.110.0050.0154.67
4.3.100.0010.0174.66
4.3.90.0030.0144.63
4.3.80.0030.0274.58
4.3.70.0020.0154.63
4.3.60.0040.0134.63
4.3.50.0010.0184.63
4.3.40.0020.0254.54
4.3.30.0020.0173.30
4.3.20.0030.0203.28
4.3.10.0030.0153.23
4.3.00.0030.01714.30

preferences:
45.58 ms | 401 KiB | 5 Q