3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @author Quyen Bui <buiquyen1995@gmail.com> */ trait LazyGetSet { private $useFluentSetter = true; /** * Change fluent setter. */ public function setFluentSetter($flag) { $this->useFluentSetter = $flag; } public function __call($method, $args) { if ((0 === strpos($method, 'get')) && ($ptyName = $this->getLazyPropertyName($method))) { return $this->lazyGet($ptyName, $args); } if ((0 === strpos($method, 'set')) && ($ptyName = $this->getLazyPropertyName($method))) { return $this->lazySet($ptyName, $args); } } /** * Detect property name from setter/getter methods. */ private function getLazyPropertyName($method) { $ptyName = lcfirst(substr($method, 3)); if (property_exists($this, $ptyName)) { return $ptyName; } } /** * Get property value */ private function lazyGet($ptyName) { return $this->{$ptyName}; } /** * Inject property value. * * @param string $ptyName * @param mixed[] $args * @return null|self */ private function lazySet($ptyName, $args) { $this->{$ptyName} = $args[0]; if ($this->useFluentSetter) { return $this; } } } // --------------------- /// Demo // --------------------- class MyClass { use LazyGetSet; private $name; } echo (new MyClass())->setName(123)->getName();

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.130.0040.00418.69
8.3.120.0040.00420.73
8.3.110.0040.00716.57
8.3.100.0000.01016.74
8.3.90.0000.00826.77
8.3.80.0030.00616.50
8.3.70.0160.00016.88
8.3.60.0100.00716.63
8.3.50.0120.00522.12
8.3.40.0160.00018.63
8.3.30.0140.00719.13
8.3.20.0050.00320.34
8.3.10.0040.00420.52
8.3.00.0030.00519.38
8.2.250.0030.00516.68
8.2.240.0040.00417.44
8.2.230.0030.00520.94
8.2.220.0040.00424.06
8.2.210.0140.00326.77
8.2.200.0070.00716.63
8.2.190.0150.00418.41
8.2.180.0190.00016.50
8.2.170.0040.01122.96
8.2.160.0120.00320.43
8.2.150.0000.00724.18
8.2.140.0030.00624.66
8.2.130.0000.00726.16
8.2.120.0000.00821.10
8.2.110.0040.00722.30
8.2.100.0040.00817.84
8.2.90.0070.00019.36
8.2.80.0050.00317.97
8.2.70.0040.00417.75
8.2.60.0060.00317.93
8.2.50.0040.00418.07
8.2.40.0000.00818.22
8.2.30.0000.00719.51
8.2.20.0040.00417.74
8.2.10.0040.00418.16
8.2.00.0000.00817.75
8.1.300.0030.00616.16
8.1.290.0030.00630.84
8.1.280.0100.01025.92
8.1.270.0040.00422.14
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0040.00723.84
8.1.230.0040.00720.90
8.1.220.0000.00817.76
8.1.210.0060.00318.77
8.1.200.0060.00317.23
8.1.190.0090.00017.23
8.1.180.0030.00518.10
8.1.170.0060.00318.65
8.1.160.0080.00022.08
8.1.150.0000.00818.85
8.1.140.0040.00417.50
8.1.130.0030.00517.82
8.1.120.0080.00017.53
8.1.110.0040.00417.50
8.1.100.0030.00517.58
8.1.90.0040.00417.59
8.1.80.0070.00017.52
8.1.70.0000.00717.46
8.1.60.0000.00817.52
8.1.50.0090.00017.61
8.1.40.0040.00417.56
8.1.30.0050.00317.54
8.1.20.0000.00717.66
8.1.10.0020.00517.61
8.1.00.0050.00217.45
8.0.300.0030.00618.77
8.0.290.0040.00416.88
8.0.280.0000.00718.55
8.0.270.0040.00416.95
8.0.260.0030.00317.31
8.0.250.0000.00716.98
8.0.240.0040.00417.04
8.0.230.0030.00317.01
8.0.220.0030.00316.98
8.0.210.0040.00716.99
8.0.200.0030.00316.92
8.0.190.0040.00417.00
8.0.180.0030.00317.00
8.0.170.0040.00416.98
8.0.160.0040.00416.90
8.0.150.0000.00716.71
8.0.140.0040.00416.89
8.0.130.0000.00613.44
8.0.120.0030.00516.88
8.0.110.0040.00416.86
8.0.100.0070.00016.98
8.0.90.0000.00716.84
8.0.80.0030.01316.94
8.0.70.0000.00817.00
8.0.60.0000.00716.95
8.0.50.0000.00717.01
8.0.30.0100.01117.07
8.0.20.0100.00917.40
8.0.10.0060.00316.97
8.0.00.0100.00816.80
7.4.330.0050.00015.00
7.4.320.0000.00616.63
7.4.300.0060.00016.65
7.4.290.0030.00316.46
7.4.280.0040.00416.55
7.4.270.0040.00416.70
7.4.260.0030.00316.64
7.4.250.0070.00016.65
7.4.240.0040.00416.58
7.4.230.0040.00416.53
7.4.220.0180.00716.76
7.4.210.0030.01016.55
7.4.200.0070.00016.66
7.4.160.0150.00616.60
7.4.150.0100.01017.40
7.4.140.0050.01217.86
7.4.130.0140.00416.66
7.4.120.0080.00916.77
7.4.110.0100.00716.68
7.4.100.0090.00916.73
7.4.90.0110.00616.54
7.4.80.0040.01319.39
7.4.70.0080.01216.55
7.4.60.0090.01316.57
7.4.50.0030.00516.46
7.4.40.0030.01216.66
7.4.30.0160.00016.77
7.4.00.0000.01615.02
7.3.330.0030.00313.21
7.3.320.0030.00313.37
7.3.310.0030.00316.29
7.3.300.0030.00316.26
7.3.290.0110.00916.41
7.3.280.0050.01116.42
7.3.270.0130.00917.40
7.3.260.0080.00816.45
7.3.250.0130.00416.41
7.3.240.0100.00816.68
7.3.230.0070.01016.39
7.3.210.0120.00916.54
7.3.200.0030.01319.39
7.3.190.0110.00616.45
7.3.180.0040.01216.55
7.3.170.0170.00316.59
7.3.160.0060.01016.52
7.2.330.0060.01116.44
7.2.320.0160.00716.43
7.2.310.0070.01116.84
7.2.300.0110.00716.81
7.2.290.0030.01916.49
7.2.00.0060.00619.15
7.1.100.0000.00818.19
7.1.70.0030.00517.09
7.1.60.0090.01619.61
7.1.50.0140.01017.02
7.1.00.0070.07322.48
7.0.200.0000.01016.75
7.0.140.0030.07022.15
7.0.70.0070.08021.66
7.0.60.0030.08721.77
7.0.50.0030.08722.19
7.0.40.0000.08720.08
7.0.30.0070.05320.07
7.0.20.0000.09320.14
7.0.10.0100.08320.12
7.0.00.0070.08720.14
5.6.280.0130.06720.86
5.6.220.0030.04720.63
5.6.210.0000.05320.78
5.6.200.0100.08321.05
5.6.190.0000.09021.13
5.6.180.0000.07020.97
5.6.170.0030.05321.12
5.6.160.0030.05321.11
5.6.150.0070.04021.01
5.6.140.0000.09021.03
5.6.130.0070.08321.11
5.6.120.0030.09321.11
5.6.110.0030.06721.02
5.6.100.0030.06720.93
5.6.90.0030.07721.01
5.6.80.0100.07720.57
5.6.70.0130.07720.46
5.6.60.0000.08320.42
5.6.50.0030.08020.47
5.6.40.0070.08320.37
5.6.30.0070.08320.54
5.6.20.0100.07020.40
5.6.10.0030.08020.40
5.6.00.0070.07720.30
5.5.360.0130.05320.41
5.5.350.0000.05320.35
5.5.340.0130.08020.88
5.5.330.0000.08720.93
5.5.320.0030.08320.81
5.5.310.0130.07720.84
5.5.300.0030.04020.79
5.5.290.0070.08320.93
5.5.280.0100.07320.73
5.5.270.0130.08020.93
5.5.260.0070.09020.91
5.5.250.0170.07020.57
5.5.240.0170.07020.27
5.5.230.0070.08320.22
5.5.220.0070.07320.11
5.5.210.0130.05720.18
5.5.200.0100.07320.01
5.5.190.0070.08020.20
5.5.180.0130.07320.27
5.5.160.0070.05320.16
5.5.150.0000.06720.22
5.5.140.0030.07720.19
5.5.130.0070.08320.14
5.5.120.0000.09020.20
5.5.110.0070.05020.18
5.5.100.0070.08320.17
5.5.90.0070.05020.18
5.5.80.0070.03320.02
5.5.70.0070.07720.07
5.5.60.0000.08320.06
5.5.50.0070.08020.11
5.5.40.0030.06020.06
5.5.30.0130.04320.15
5.5.20.0070.07720.05
5.5.10.0000.04320.11
5.5.00.0030.06320.11
5.4.450.0030.08719.36
5.4.440.0030.09019.45
5.4.430.0030.06719.36
5.4.420.0000.08319.41
5.4.410.0030.08319.04
5.4.400.0100.07018.86
5.4.390.0000.08718.87
5.4.380.0070.04719.12
5.4.370.0000.08319.16
5.4.360.0000.08318.85
5.4.350.0000.08019.23
5.4.340.0070.06319.09
5.4.320.0030.05718.85
5.4.310.0030.07019.18
5.4.300.0000.08318.84
5.4.290.0030.06719.23
5.4.280.0030.08018.87
5.4.270.0030.07719.21
5.4.260.0100.06319.14
5.4.250.0070.07319.08
5.4.240.0030.08018.87
5.4.230.0030.05718.87
5.4.220.0100.07319.04
5.4.210.0000.05719.20
5.4.200.0030.07019.25
5.4.190.0030.05018.93
5.4.180.0030.06019.13
5.4.170.0070.07719.20
5.4.160.0130.07019.02
5.4.150.0200.06719.18
5.4.140.0100.07716.41
5.4.130.0100.06716.40
5.4.120.0000.08016.45
5.4.110.0070.07016.46
5.4.100.0070.06016.45
5.4.90.0070.06016.39
5.4.80.0030.07316.47
5.4.70.0070.07316.51
5.4.60.0030.07016.36
5.4.50.0030.06016.42
5.4.40.0070.05016.30
5.4.30.0100.06716.32
5.4.20.0070.05016.25
5.4.10.0030.07716.33
5.4.00.0000.07715.85
5.3.290.0030.04014.53
5.3.280.0070.08014.59
5.3.270.0030.08014.54
5.3.260.0000.08014.47
5.3.250.0100.05014.46
5.3.240.0100.07314.55
5.3.230.0030.08314.46
5.3.220.0000.08014.43
5.3.210.0070.07314.48
5.3.200.0030.08014.53
5.3.190.0030.06714.58
5.3.180.0000.08314.41
5.3.170.0030.07714.41
5.3.160.0100.07314.52
5.3.150.0170.06714.43
5.3.140.0030.08014.41
5.3.130.0100.07714.50
5.3.120.0030.08314.51
5.3.110.0000.08314.51
5.3.100.0000.06014.00
5.3.90.0030.07313.96
5.3.80.0070.07313.99
5.3.70.0100.06313.79
5.3.60.0000.07713.91
5.3.50.0070.06013.91
5.3.40.0000.07713.93
5.3.30.0200.06313.91
5.3.20.0070.06313.55
5.3.10.0070.06313.57
5.3.00.0000.06713.62
5.2.170.0000.06012.32
5.2.160.0000.06012.32
5.2.150.0030.06312.32
5.2.140.0030.06312.32
5.2.130.0070.06012.32
5.2.120.0030.06012.32
5.2.110.0030.04712.32
5.2.100.0000.06012.32
5.2.90.0070.03012.32
5.2.80.0030.02712.32
5.2.70.0000.03012.32
5.2.60.0000.03012.32
5.2.50.0000.04312.32
5.2.40.0030.04012.32
5.2.30.0100.02012.32
5.2.20.0000.03012.32
5.2.10.0030.02712.32
5.2.00.0000.03012.32
5.1.60.0000.04012.32
5.1.50.0030.03712.32
5.1.40.0030.04012.32
5.1.30.0030.05312.32
5.1.20.0030.04312.32
5.1.10.0030.03312.32
5.1.00.0030.03312.32
5.0.50.0000.04312.32
5.0.40.0070.03312.32
5.0.30.0000.06012.32
5.0.20.0030.03712.32
5.0.10.0070.04012.32
5.0.00.0030.06012.32
4.4.90.0030.01312.32
4.4.80.0030.03312.32
4.4.70.0000.03312.32
4.4.60.0000.02312.32
4.4.50.0000.01712.32
4.4.40.0030.03712.32
4.4.30.0030.03012.32
4.4.20.0000.02712.32
4.4.10.0000.02312.32
4.4.00.0000.06012.32
4.3.110.0030.02712.32
4.3.100.0000.02012.32
4.3.90.0000.03312.32
4.3.80.0000.05312.32
4.3.70.0000.04012.32
4.3.60.0000.03712.32
4.3.50.0000.03712.32
4.3.40.0030.05012.32
4.3.30.0070.03312.32
4.3.20.0000.03712.32
4.3.10.0000.04012.32
4.3.00.0000.03712.32

preferences:
33.14 ms | 403 KiB | 5 Q