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 test; 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.60.0140.00718.56
8.3.50.0110.00721.94
8.3.40.0070.00718.75
8.3.30.0100.00718.98
8.3.20.0080.00020.20
8.3.10.0030.00620.36
8.3.00.0080.00019.09
8.2.180.0110.00316.50
8.2.170.0100.00322.96
8.2.160.0070.00720.43
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0000.00726.16
8.2.120.0040.00421.95
8.2.110.0090.01520.94
8.2.100.0110.00017.74
8.2.90.0080.00019.14
8.2.80.0030.00717.97
8.2.70.0080.00017.38
8.2.60.0040.00417.68
8.2.50.0090.00018.10
8.2.40.0000.00820.55
8.2.30.0000.00719.16
8.2.20.0020.00517.60
8.2.10.0060.00317.89
8.2.00.0000.00817.59
8.1.280.0110.00725.92
8.1.270.0030.00623.91
8.1.260.0080.00026.35
8.1.250.0000.00728.09
8.1.240.0120.00922.19
8.1.230.0030.00717.77
8.1.220.0040.00417.74
8.1.210.0080.00018.77
8.1.200.0030.00717.10
8.1.190.0040.00417.10
8.1.180.0050.00318.10
8.1.170.0040.00418.46
8.1.160.0040.00421.94
8.1.150.0000.00718.71
8.1.140.0040.00417.40
8.1.130.0030.00317.68
8.1.120.0080.00017.33
8.1.110.0000.00817.25
8.1.100.0000.00717.36
8.1.90.0000.00817.39
8.1.80.0040.00417.27
8.1.70.0000.00717.32
8.1.60.0040.00417.46
8.1.50.0000.00817.45
8.1.40.0040.00417.42
8.1.30.0040.00417.50
8.1.20.0040.00417.52
8.1.10.0000.00817.36
8.1.00.0070.00017.33
8.0.300.0070.00418.77
8.0.290.0110.00016.58
8.0.280.0040.00418.40
8.0.270.0000.00717.05
8.0.260.0030.00317.25
8.0.250.0000.00716.98
8.0.240.0000.00716.89
8.0.230.0070.00016.84
8.0.220.0000.00716.76
8.0.210.0030.00316.73
8.0.200.0000.00616.91
8.0.190.0070.00016.93
8.0.180.0040.00416.85
8.0.170.0090.00016.78
8.0.160.0030.00416.77
8.0.150.0000.00716.87
8.0.140.0000.00716.82
8.0.130.0040.00513.33
8.0.120.0000.00816.74
8.0.110.0000.00716.70
8.0.100.0080.00016.84
8.0.90.0000.00716.76
8.0.80.0000.01616.82
8.0.70.0030.00516.81
8.0.60.0000.00816.70
8.0.50.0040.00416.75
8.0.30.0120.00617.05
8.0.20.0130.01017.40
8.0.10.0080.00017.10
8.0.00.0090.01216.72
7.4.330.0000.00515.00
7.4.320.0030.00316.61
7.4.300.0000.00716.50
7.4.290.0040.00416.46
7.4.280.0050.00316.54
7.4.270.0000.00716.58
7.4.260.0040.00416.45
7.4.250.0040.00416.44
7.4.240.0060.00216.43
7.4.230.0030.00316.36
7.4.220.0090.01216.52
7.4.210.0030.01216.46
7.4.200.0000.00816.48
7.4.160.0130.00616.70
7.4.150.0120.00717.40
7.4.140.0120.00517.86
7.4.130.0120.00516.52
7.4.120.0070.01116.46
7.4.110.0060.01216.46
7.4.100.0090.01316.21
7.4.90.0090.00916.38
7.4.80.0060.01018.80
7.4.70.0030.01316.58
7.4.60.0120.00916.42
7.4.50.0030.00616.33
7.4.40.0100.01716.43
7.4.30.0180.00516.63
7.3.330.0030.00313.23
7.3.320.0000.00613.25
7.3.310.0030.00316.33
7.3.300.0030.00316.28
7.3.290.0090.00616.29
7.3.280.0080.00716.26
7.3.270.0060.01217.40
7.3.260.0070.01716.48
7.3.250.0120.00716.39
7.3.240.0090.00916.43
7.3.230.0100.00716.39
7.3.210.0150.00316.34
7.3.200.0100.01019.39
7.3.190.0190.00316.43
7.3.180.0120.00616.32
7.3.170.0120.00416.49
7.3.160.0110.00616.29
7.2.330.0150.00316.49
7.2.320.0100.01016.27
7.2.310.0100.00716.54
7.2.300.0140.00716.66
7.2.290.0060.01016.64
5.4.320.0080.03312.53
5.4.310.0090.04212.53
5.4.300.0060.04012.54
5.4.290.0060.03812.53
5.4.280.0070.03512.43
5.4.270.0080.03612.42
5.4.260.0060.03912.43
5.4.250.0070.03612.43
5.4.240.0040.03612.43
5.4.230.0080.04112.41
5.4.220.0060.03412.42
5.4.210.0050.03612.42
5.4.200.0040.03812.41
5.4.190.0070.03812.41
5.4.180.0060.03612.41
5.4.170.0040.03712.42
5.4.160.0080.04112.42
5.4.150.0080.03912.42
5.4.140.0070.03612.10
5.4.130.0070.03912.09
5.4.120.0070.03812.05
5.4.110.0040.03812.04
5.4.100.0090.03712.04
5.4.90.0050.03612.04
5.4.80.0120.03812.04
5.4.70.0060.03312.04
5.4.60.0060.03412.04
5.4.50.0060.03812.04
5.4.40.0070.03712.03
5.4.30.0060.03512.02
5.4.20.0060.03412.02
5.4.10.0040.03612.02
5.4.00.0040.03711.52
5.3.290.0080.04012.80
5.3.280.0050.03712.71
5.3.270.0040.03912.73
5.3.260.0060.04112.72
5.3.250.0060.03612.72
5.3.240.0070.03612.72
5.3.230.0090.04012.71
5.3.220.0090.03412.68
5.3.210.0040.04412.68
5.3.200.0100.03512.68
5.3.190.0060.03912.68
5.3.180.0050.04612.68
5.3.170.0100.03712.67
5.3.160.0060.03612.68
5.3.150.0040.03912.68
5.3.140.0050.03612.66
5.3.130.0030.04012.66
5.3.120.0050.03912.66
5.3.110.0060.04112.66
5.3.100.0040.03712.12
5.3.90.0050.03612.08
5.3.80.0040.03712.07
5.3.70.0050.04112.08
5.3.60.0040.04112.07
5.3.50.0080.03912.00
5.3.40.0050.03512.00
5.3.30.0050.03411.95
5.3.20.0100.03711.73
5.3.10.0070.04111.70
5.3.00.0090.03111.68
5.2.170.0040.0339.19
5.2.160.0090.0329.19
5.2.150.0060.0309.18
5.2.140.0050.0299.18
5.2.130.0050.0289.14
5.2.120.0080.0259.14
5.2.110.0050.0289.15
5.2.100.0050.0349.14
5.2.90.0080.0289.14
5.2.80.0030.0309.14
5.2.70.0030.0469.14
5.2.60.0060.0279.09
5.2.50.0050.0289.06
5.2.40.0050.0279.04
5.2.30.0090.0319.02
5.2.20.0040.0309.01
5.2.10.0040.0308.93
5.2.00.0060.0358.78
5.1.60.0060.0448.07
5.1.50.0050.0238.07
5.1.40.0060.0258.05
5.1.30.0080.0338.40
5.1.20.0050.0268.43
5.1.10.0040.0358.14
5.1.00.0030.0268.14
5.0.50.0050.0256.63
5.0.40.0030.0276.48
5.0.30.0020.0326.29
5.0.20.0040.0186.27
5.0.10.0040.0196.25
5.0.00.0020.0376.23
4.4.90.0030.0264.78
4.4.80.0010.0174.75
4.4.70.0020.0184.76
4.4.60.0020.0164.75
4.4.50.0030.0154.77
4.4.40.0040.0284.71
4.4.30.0020.0164.76
4.4.20.0000.0244.84
4.4.10.0040.0184.85
4.4.00.0040.0244.76
4.3.110.0010.0184.67
4.3.100.0030.0144.66
4.3.90.0050.0154.63
4.3.80.0010.0254.58
4.3.70.0010.0154.63
4.3.60.0040.0134.63
4.3.50.0040.0204.63
4.3.40.0030.0284.54
4.3.30.0020.0213.29
4.3.20.0030.0143.26
4.3.10.0020.0153.22
4.3.00.0170.01716.39

preferences:
64.4 ms | 401 KiB | 5 Q