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 magic accessors also need to be created for full functional completeness public function __get() { \Closure::bind(function() { $this->bar = 'Loaded from DB!'; }, $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)
5.4.320.0070.03512.54
5.4.310.0050.03812.54
5.4.300.0030.03812.54
5.4.290.0090.03512.53
5.4.280.0040.03712.43
5.4.270.0050.03712.43
5.4.260.0050.03812.43
5.4.250.0060.04012.43
5.4.240.0080.03912.43
5.4.230.0070.03612.42
5.4.220.0060.03812.42
5.4.210.0060.03412.42
5.4.200.0040.03912.42
5.4.190.0040.03712.42
5.4.180.0080.03312.42
5.4.170.0020.04012.43
5.4.160.0060.03612.42
5.4.150.0040.03812.42
5.4.140.0040.03812.10
5.4.130.0030.04112.09
5.4.120.0070.03512.04
5.4.110.0050.04412.04
5.4.100.0090.04012.04
5.4.90.0120.03412.04
5.4.80.0070.03512.04
5.4.70.0050.03512.04
5.4.60.0030.03712.04
5.4.50.0100.03112.04
5.4.40.0050.04712.02
5.4.30.0060.03512.02
5.4.20.0050.03612.02
5.4.10.0050.03512.02
5.4.00.0040.03811.51
5.3.290.0040.04112.80
5.3.280.0080.03512.72
5.3.270.0050.04012.73
5.3.260.0020.04312.73
5.3.250.0040.03812.73
5.3.240.0020.04212.73
5.3.230.0090.03512.72
5.3.220.0070.03612.69
5.3.210.0070.03712.69
5.3.200.0080.04012.68
5.3.190.0060.03912.69
5.3.180.0040.03812.68
5.3.170.0060.03612.69
5.3.160.0080.03412.68
5.3.150.0030.04112.68
5.3.140.0050.03812.68
5.3.130.0060.03912.67
5.3.120.0060.03912.67
5.3.110.0070.03812.67
5.3.100.0090.03612.16
5.3.90.0050.03712.14
5.3.80.0070.03412.13
5.3.70.0050.03712.13
5.3.60.0050.03712.11
5.3.50.0080.03412.06
5.3.40.0060.03612.06
5.3.30.0060.03612.03
5.3.20.0040.03711.81
5.3.10.0070.03311.77
5.3.00.0070.03411.75
5.2.170.0080.0279.23
5.2.160.0040.0309.23
5.2.150.0040.0319.23
5.2.140.0040.0319.22
5.2.130.0030.0309.18
5.2.120.0040.0289.19
5.2.110.0040.0299.19
5.2.100.0050.0329.19
5.2.90.0070.0279.18
5.2.80.0040.0369.18
5.2.70.0040.0309.18
5.2.60.0050.0299.14
5.2.50.0040.0309.11
5.2.40.0050.0359.08
5.2.30.0060.0359.06
5.2.20.0020.0329.05
5.2.10.0050.0288.96
5.2.00.0030.0308.82
5.1.60.0040.0258.10
5.1.50.0060.0248.09
5.1.40.0030.0258.07
5.1.30.0030.0278.43
5.1.20.0030.0288.45
5.1.10.0070.0238.17
5.1.00.0020.0278.17
5.0.50.0050.0196.65
5.0.40.0020.0206.50
5.0.30.0040.0336.32
5.0.20.0060.0166.29
5.0.10.0040.0216.27
5.0.00.0060.0316.26
4.4.90.0030.0174.78
4.4.80.0040.0144.75
4.4.70.0030.0154.75
4.4.60.0030.0154.75
4.4.50.0050.0134.77
4.4.40.0020.0254.71
4.4.30.0030.0154.76
4.4.20.0020.0164.85
4.4.10.0030.0154.85
4.4.00.0010.0274.76
4.3.110.0030.0154.66
4.3.100.0030.0224.67
4.3.90.0050.0124.63
4.3.80.0020.0244.58
4.3.70.0010.0164.63
4.3.60.0030.0144.63
4.3.50.0030.0154.63
4.3.40.0010.0254.54
4.3.30.0040.0203.30
4.3.20.0030.0163.28
4.3.10.0030.0153.24
4.3.00.0000.01714.30

preferences:
136.79 ms | 1398 KiB | 7 Q