3v4l.org

run code in 300+ PHP versions simultaneously
<?php 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. * * @todo Validate data type */ private function lazySet($ptyName, $args) { if($this->validate($ptyName, $args[0])) { $this->{$ptyName} = $args[0]; } if ($this->useFluentSetter) { return $this; } } private function validate($variable_name, $variable_value) { $hints = $this->getPropertyHintType(__CLASS__, $variable_name); if(isset($hints['@var'])) { $validateCallback = array( 'string' => 'is_string', 'integer' => 'is_integer', 'array' => 'is_array', 'float' => 'is_float', 'double' => 'is_double', 'boolean' => 'is_bool', 'object' => 'is_object', 'resource' => 'is_resource', ); if(isset($validateCallback[$hints['@var']])) { return call_user_func($validateCallback[$hints['@var']], $variable_value); } else { return $variable_value instanceof $hints['@var']; } } } public function getPropertyHintType($className, $propertyName) { $class = new ReflectionClass($className); $match = array(); $docs = array(); foreach(explode("\n",(str_replace(array('*', '/'),'', $class->getProperty($propertyName)->getDocComment()))) as $doc) { $docs[] = trim($doc); } $return = array(); foreach(array_filter($docs) as $doc) { $match = array(); preg_match('/^([@].*)\ (.*)$/', $doc, $match); if($match){ $return[$match[1]] = trim($match[2]); } } return $return; } } namespace quyentest; class MyClass { use LazyGetSet; /** * @var integer */ private $name; /** * @var MyClass */ private $instant; } //echo (new MyClass())->setName(123)->getName(); $MyClass = new MyClass(); echo $MyClass->setInstant('a')->getInstant();

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.0080.00816.75
8.3.60.0120.00618.36
8.3.50.0130.00721.93
8.3.40.0120.00318.90
8.3.30.0090.00918.84
8.3.20.0040.00420.20
8.3.10.0030.00520.39
8.3.00.0030.00519.25
8.2.180.0040.01116.88
8.2.170.0110.00322.96
8.2.160.0130.00020.53
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0000.00826.16
8.2.120.0020.00522.14
8.2.110.0090.00021.13
8.2.100.0090.00320.46
8.2.90.0000.00919.21
8.2.80.0080.00017.97
8.2.70.0040.00417.80
8.2.60.0040.00417.91
8.2.50.0080.00018.10
8.2.40.0000.00820.61
8.2.30.0050.00319.29
8.2.20.0000.00717.53
8.2.10.0000.00817.82
8.2.00.0060.00317.57
8.1.280.0140.00325.92
8.1.270.0060.00323.97
8.1.260.0080.00026.35
8.1.250.0050.00228.09
8.1.240.0070.01022.05
8.1.230.0040.00719.17
8.1.220.0040.00417.74
8.1.210.0050.00318.77
8.1.200.0030.00617.23
8.1.190.0030.00617.11
8.1.180.0080.00018.10
8.1.170.0040.00418.43
8.1.160.0060.00322.05
8.1.150.0040.00418.76
8.1.140.0000.00817.32
8.1.130.0050.00317.78
8.1.120.0040.00417.38
8.1.110.0040.00417.35
8.1.100.0070.00017.20
8.1.90.0030.00517.32
8.1.80.0040.00417.29
8.1.70.0000.00717.28
8.1.60.0030.00517.48
8.1.50.0000.00817.49
8.1.40.0040.00417.32
8.1.30.0030.00517.59
8.1.20.0000.00817.46
8.1.10.0030.00517.46
8.1.00.0050.00317.37
8.0.300.0040.00419.69
8.0.290.0030.00616.63
8.0.280.0050.00318.36
8.0.270.0000.00717.16
8.0.260.0000.00617.16
8.0.250.0000.00716.82
8.0.240.0040.00416.92
8.0.230.0030.00316.90
8.0.220.0000.00716.72
8.0.210.0070.00016.80
8.0.200.0040.00416.97
8.0.190.0040.00416.82
8.0.180.0040.00416.81
8.0.170.0080.00016.89
8.0.160.0000.00716.82
8.0.150.0000.00816.84
8.0.140.0070.00016.84
8.0.130.0030.00613.26
8.0.120.0040.00416.81
8.0.110.0070.00016.83
8.0.100.0000.00816.81
8.0.90.0000.00816.65
8.0.80.0060.01516.90
8.0.70.0040.00416.68
8.0.60.0000.00716.77
8.0.50.0040.00416.75
8.0.30.0110.01117.00
8.0.20.0080.01117.40
8.0.10.0000.00817.03
8.0.00.0100.00716.63
7.4.330.0030.00315.07
7.4.320.0030.00316.47
7.4.300.0030.00316.42
7.4.290.0000.00616.37
7.4.280.0040.00416.46
7.4.270.0060.00016.50
7.4.260.0070.00016.47
7.4.250.0100.00016.43
7.4.240.0020.00616.55
7.4.230.0000.00716.67
7.4.220.0000.01816.34
7.4.210.0000.01416.48
7.4.200.0030.00316.27
7.4.160.0200.00316.62
7.4.150.0100.01017.40
7.4.140.0100.00717.86
7.4.130.0070.01116.53
7.4.120.0080.01316.46
7.4.110.0150.00316.63
7.4.100.0070.01016.41
7.4.90.0040.01416.23
7.4.80.0070.01718.80
7.4.70.0130.00316.48
7.4.60.0140.00416.38
7.4.50.0080.00016.30
7.4.40.0040.01816.33
7.4.30.0100.01316.66
7.3.330.0000.00613.05
7.3.320.0030.00313.29
7.3.310.0000.00716.38
7.3.300.0060.00016.29
7.3.290.0130.01016.23
7.3.280.0110.00616.27
7.3.270.0070.01817.40
7.3.260.0180.00016.41
7.3.250.0110.00816.41
7.3.240.0080.01516.51
7.3.230.0060.01116.39
7.3.210.0090.00916.35
7.3.200.0070.01719.39
7.3.190.0100.00716.29
7.3.180.0210.01616.34
7.3.170.0080.00816.32
7.3.160.0090.00916.29
7.2.330.0140.00416.26
7.2.320.0180.00016.31
7.2.310.0070.01016.50
7.2.300.0030.01416.54
7.2.290.0140.00316.45
5.4.320.0040.03812.53
5.4.310.0040.04012.53
5.4.300.0100.03212.54
5.4.290.0060.03712.53
5.4.280.0050.03512.42
5.4.270.0050.03612.43
5.4.260.0110.03312.42
5.4.250.0040.03812.42
5.4.240.0060.03912.42
5.4.230.0020.04112.41
5.4.220.0040.03712.41
5.4.210.0040.03612.42
5.4.200.0060.04012.41
5.4.190.0050.03612.41
5.4.180.0080.03312.41
5.4.170.0060.03812.43
5.4.160.0080.03212.42
5.4.150.0030.03712.41
5.4.140.0130.03812.10
5.4.130.0060.03412.09
5.4.120.0040.03612.04
5.4.110.0100.04112.05
5.4.100.0070.03412.04
5.4.90.0030.03812.04
5.4.80.0060.04312.04
5.4.70.0040.03912.04
5.4.60.0060.03912.04
5.4.50.0080.03812.04
5.4.40.0050.04212.03
5.4.30.0070.03312.02
5.4.20.0060.03312.02
5.4.10.0100.02912.02
5.4.00.0040.04211.52
5.3.290.0090.03912.80
5.3.280.0030.03912.71
5.3.270.0030.04112.72
5.3.260.0070.03712.72
5.3.250.0070.04112.72
5.3.240.0080.03612.72
5.3.230.0090.03612.71
5.3.220.0070.03412.68
5.3.210.0080.03612.68
5.3.200.0040.04312.68
5.3.190.0100.03412.68
5.3.180.0090.04012.67
5.3.170.0080.03312.67
5.3.160.0090.04012.68
5.3.150.0080.03912.67
5.3.140.0060.03712.66
5.3.130.0070.03812.66
5.3.120.0060.03912.66
5.3.110.0130.03312.66
5.3.100.0070.03412.12
5.3.90.0080.04412.08
5.3.80.0060.03412.07
5.3.70.0100.03012.07
5.3.60.0040.03612.06
5.3.50.0030.03712.00
5.3.40.0070.03312.00
5.3.30.0060.03511.95
5.3.20.0050.03811.73
5.3.10.0070.03611.70
5.3.00.0020.03711.68
5.2.170.0050.0299.18
5.2.160.0040.0379.19
5.2.150.0040.0309.19
5.2.140.0060.0389.18
5.2.130.0050.0279.14
5.2.120.0040.0339.14
5.2.110.0060.0359.15
5.2.100.0060.0359.14
5.2.90.0060.0329.14
5.2.80.0040.0379.14
5.2.70.0060.0389.14
5.2.60.0080.0309.09
5.2.50.0040.0379.06
5.2.40.0050.0319.04
5.2.30.0060.0369.02
5.2.20.0050.0349.01
5.2.10.0080.0318.93
5.2.00.0080.0288.78
5.1.60.0040.0318.07
5.1.50.0050.0328.06
5.1.40.0070.0218.05
5.1.30.0040.0278.39
5.1.20.0040.0268.42
5.1.10.0040.0298.14
5.1.00.0070.0258.15
5.0.50.0060.0236.63
5.0.40.0030.0256.48
5.0.30.0040.0326.30
5.0.20.0040.0196.27
5.0.10.0030.0196.25
5.0.00.0030.0306.24
4.4.90.0050.0204.78
4.4.80.0040.0144.75
4.4.70.0020.0154.75
4.4.60.0030.0174.76
4.4.50.0010.0184.77
4.4.40.0020.0254.71
4.4.30.0010.0174.75
4.4.20.0020.0164.84
4.4.10.0030.0154.85
4.4.00.0020.0264.76
4.3.110.0030.0194.67
4.3.100.0000.0164.66
4.3.90.0070.0174.63
4.3.80.0010.0254.58
4.3.70.0030.0174.63
4.3.60.0030.0154.63
4.3.50.0020.0174.63
4.3.40.0030.0294.54
4.3.30.0020.0233.29
4.3.20.0020.0323.26
4.3.10.0030.0183.22
4.3.00.0030.0236.98

preferences:
83.31 ms | 401 KiB | 5 Q