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.0040.01118.51
8.3.60.0110.00318.30
8.3.50.0150.00421.99
8.3.40.0070.00718.61
8.3.30.0040.01519.09
8.3.20.0080.00020.29
8.3.10.0040.00420.58
8.3.00.0000.00819.13
8.2.190.0060.01016.58
8.2.180.0100.01018.29
8.2.170.0040.01122.96
8.2.160.0080.00818.83
8.2.150.0030.00624.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0070.00022.06
8.2.110.0070.00421.07
8.2.100.0060.00617.74
8.2.90.0030.00518.83
8.2.80.0040.00417.97
8.2.70.0050.00317.50
8.2.60.0080.00017.80
8.2.50.0000.00918.10
8.2.40.0050.00320.59
8.2.30.0000.00719.16
8.2.20.0030.00517.58
8.2.10.0030.00518.01
8.2.00.0080.00017.58
8.1.280.0100.01025.92
8.1.270.0060.00323.96
8.1.260.0080.00026.35
8.1.250.0070.00028.09
8.1.240.0000.01022.24
8.1.230.0120.00017.64
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0060.00317.13
8.1.190.0000.00817.22
8.1.180.0030.00618.10
8.1.170.0040.00418.66
8.1.160.0050.00321.91
8.1.150.0040.00418.80
8.1.140.0040.00417.46
8.1.130.0030.00317.68
8.1.120.0000.00717.27
8.1.110.0000.00817.34
8.1.100.0040.00417.21
8.1.90.0030.00717.40
8.1.80.0050.00317.38
8.1.70.0030.00317.29
8.1.60.0000.00817.53
8.1.50.0000.00817.45
8.1.40.0000.00717.32
8.1.30.0040.00417.54
8.1.20.0050.00317.49
8.1.10.0050.00317.41
8.1.00.0000.00717.25
8.0.300.0000.01018.77
8.0.290.0030.00616.63
8.0.280.0030.00318.35
8.0.270.0000.00817.16
8.0.260.0000.00617.18
8.0.250.0000.00816.95
8.0.240.0000.00716.94
8.0.230.0030.00316.99
8.0.220.0000.00716.87
8.0.210.0030.00316.88
8.0.200.0070.00016.89
8.0.190.0000.00816.86
8.0.180.0040.00416.83
8.0.170.0000.00816.77
8.0.160.0030.00316.73
8.0.150.0000.00716.70
8.0.140.0040.00416.74
8.0.130.0040.00413.29
8.0.120.0040.00416.83
8.0.110.0040.00416.77
8.0.100.0000.00716.74
8.0.90.0070.00016.91
8.0.80.0110.00716.81
8.0.70.0050.00316.98
8.0.60.0070.00016.77
8.0.50.0000.00816.86
8.0.30.0150.00516.97
8.0.20.0060.01217.40
8.0.10.0000.00716.94
8.0.00.0130.00416.89
7.4.330.0000.00515.11
7.4.320.0030.00316.81
7.4.300.0060.00016.82
7.4.290.0000.00716.86
7.4.280.0030.00616.85
7.4.270.0030.00316.72
7.4.260.0040.00316.78
7.4.250.0000.00816.71
7.4.240.0020.00516.79
7.4.230.0030.00316.64
7.4.220.0130.00716.86
7.4.210.0060.00916.92
7.4.200.0070.00016.65
7.4.160.0130.00316.73
7.4.150.0140.01017.40
7.4.140.0090.00817.86
7.4.130.0100.00716.69
7.4.120.0110.00616.62
7.4.110.0070.01016.63
7.4.100.0120.00916.69
7.4.90.0090.00916.90
7.4.80.0070.01018.80
7.4.70.0100.01316.85
7.4.60.0000.01716.59
7.4.50.0030.00516.73
7.4.40.0100.00716.60
7.4.30.0060.01616.66
7.3.330.0060.00013.27
7.3.320.0030.00313.10
7.3.310.0000.00716.30
7.3.300.0030.00316.23
7.3.290.0100.00716.28
7.3.280.0100.00816.27
7.3.270.0000.01717.40
7.3.260.0120.00916.31
7.3.250.0050.01216.29
7.3.240.0100.01316.47
7.3.230.0060.00916.39
7.3.210.0080.01216.29
7.3.200.0120.00619.39
7.3.190.0070.01516.49
7.3.180.0040.01516.29
7.3.170.0020.01416.51
7.3.160.0060.01016.28
7.2.330.0110.00816.50
7.2.320.0030.01516.60
7.2.310.0090.01216.48
7.2.300.0100.00716.20
7.2.290.0090.00916.60
5.4.320.0070.04012.54
5.4.310.0050.04112.53
5.4.300.0080.03612.54
5.4.290.0050.03912.53
5.4.280.0060.03412.43
5.4.270.0040.03812.42
5.4.260.0010.04212.42
5.4.250.0030.04012.42
5.4.240.0040.04112.43
5.4.230.0080.03612.42
5.4.220.0070.03512.41
5.4.210.0050.03512.41
5.4.200.0070.04212.42
5.4.190.0060.03612.41
5.4.180.0060.03512.41
5.4.170.0070.04212.42
5.4.160.0060.03512.42
5.4.150.0040.03812.42
5.4.140.0070.03512.10
5.4.130.0030.04412.09
5.4.120.0100.03012.04
5.4.110.0050.03612.05
5.4.100.0080.03712.04
5.4.90.0040.03812.04
5.4.80.0020.04012.04
5.4.70.0050.03412.04
5.4.60.0060.03912.04
5.4.50.0040.03712.04
5.4.40.0050.03612.03
5.4.30.0070.03612.02
5.4.20.0060.03412.02
5.4.10.0040.03512.02
5.4.00.0050.04111.51
5.3.290.0080.04012.80
5.3.280.0080.03712.71
5.3.270.0060.03912.72
5.3.260.0100.04412.72
5.3.250.0060.03712.72
5.3.240.0050.04112.72
5.3.230.0050.04012.71
5.3.220.0050.03612.68
5.3.210.0040.04712.68
5.3.200.0060.03512.68
5.3.190.0070.04112.67
5.3.180.0110.03512.67
5.3.170.0070.04512.67
5.3.160.0040.03812.67
5.3.150.0100.03812.67
5.3.140.0090.03112.66
5.3.130.0030.04112.66
5.3.120.0070.03712.66
5.3.110.0080.03512.65
5.3.100.0090.03812.12
5.3.90.0060.05112.08
5.3.80.0070.04212.07
5.3.70.0060.03512.08
5.3.60.0050.03612.07
5.3.50.0060.03512.00
5.3.40.0070.04112.00
5.3.30.0070.03811.95
5.3.20.0050.03711.73
5.3.10.0060.03911.70
5.3.00.0050.03511.68
5.2.170.0070.0279.18
5.2.160.0060.0269.19
5.2.150.0050.0309.18
5.2.140.0040.0309.18
5.2.130.0060.0279.14
5.2.120.0040.0289.14
5.2.110.0040.0299.15
5.2.100.0080.0249.14
5.2.90.0040.0289.15
5.2.80.0050.0299.14
5.2.70.0040.0299.14
5.2.60.0010.0339.10
5.2.50.0040.0309.06
5.2.40.0030.0299.04
5.2.30.0050.0409.01
5.2.20.0060.0329.01
5.2.10.0020.0298.93
5.2.00.0030.0338.79
5.1.60.0010.0268.07
5.1.50.0050.0238.06
5.1.40.0030.0248.05
5.1.30.0010.0358.40
5.1.20.0070.0278.42
5.1.10.0070.0328.14
5.1.00.0030.0328.14
5.0.50.0040.0256.63
5.0.40.0040.0256.48
5.0.30.0030.0316.29
5.0.20.0060.0186.26
5.0.10.0030.0206.24
5.0.00.0050.0336.23
4.4.90.0030.0174.78
4.4.80.0030.0174.75
4.4.70.0020.0154.75
4.4.60.0040.0204.75
4.4.50.0040.0184.77
4.4.40.0030.0294.71
4.4.30.0020.0274.76
4.4.20.0030.0214.85
4.4.10.0020.0154.85
4.4.00.0020.0244.76
4.3.110.0020.0154.67
4.3.100.0050.0124.67
4.3.90.0020.0174.63
4.3.80.0040.0274.58
4.3.70.0010.0164.63
4.3.60.0070.0174.63
4.3.50.0030.0204.63
4.3.40.0050.0264.54
4.3.30.0010.0223.29
4.3.20.0020.0203.26
4.3.10.0030.0223.22
4.3.00.0000.01316.39

preferences:
50.34 ms | 401 KiB | 5 Q