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 var_dump($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; } } 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.0040.01518.02
8.3.50.0150.00822.10
8.3.40.0040.01118.67
8.3.30.0130.00718.98
8.3.20.0040.00420.16
8.3.10.0080.00020.40
8.3.00.0060.00319.38
8.2.180.0110.01116.50
8.2.170.0030.01022.96
8.2.160.0070.00720.33
8.2.150.0030.00524.18
8.2.140.0080.00024.66
8.2.130.0070.00026.16
8.2.120.0000.00819.64
8.2.110.0060.00322.12
8.2.100.0120.00018.01
8.2.90.0080.00019.08
8.2.80.0130.00017.97
8.2.70.0000.00817.50
8.2.60.0070.00417.77
8.2.50.0040.00418.07
8.2.40.0040.00418.09
8.2.30.0040.00419.18
8.2.20.0040.00417.52
8.2.10.0040.00418.01
8.2.00.0030.00617.56
8.1.280.0070.01125.92
8.1.270.0050.00321.96
8.1.260.0040.00426.35
8.1.250.0050.00328.09
8.1.240.0060.00322.21
8.1.230.0110.00017.64
8.1.220.0030.00517.74
8.1.210.0080.00018.77
8.1.200.0030.00617.22
8.1.190.0000.00817.13
8.1.180.0040.00418.10
8.1.170.0080.00018.41
8.1.160.0030.00521.91
8.1.150.0000.00718.80
8.1.140.0040.00417.32
8.1.130.0040.00417.85
8.1.120.0080.00017.41
8.1.110.0040.00417.33
8.1.100.0040.00417.31
8.1.90.0000.00717.39
8.1.80.0030.00317.40
8.1.70.0030.00317.34
8.1.60.0000.00817.55
8.1.50.0040.00417.46
8.1.40.0000.00817.47
8.1.30.0050.00317.45
8.1.20.0070.00017.63
8.1.10.0030.00617.47
8.1.00.0060.00317.36
8.0.300.0050.00318.77
8.0.290.0080.00016.63
8.0.280.0050.00318.41
8.0.270.0000.00717.20
8.0.260.0030.00317.15
8.0.250.0070.00016.96
8.0.240.0050.00316.96
8.0.230.0030.00316.90
8.0.220.0000.00716.84
8.0.210.0030.00316.83
8.0.200.0030.00316.80
8.0.190.0000.00716.91
8.0.180.0080.00016.77
8.0.170.0000.00716.95
8.0.160.0050.00216.74
8.0.150.0000.00816.73
8.0.140.0070.00016.73
8.0.130.0050.00313.32
8.0.120.0040.00416.73
8.0.110.0000.00816.76
8.0.100.0040.00416.65
8.0.90.0000.00816.87
8.0.80.0000.01616.85
8.0.70.0040.00416.74
8.0.60.0000.00716.79
8.0.50.0060.00316.73
8.0.30.0080.01117.22
8.0.20.0170.00717.40
8.0.10.0050.00216.97
8.0.00.0070.01216.81
7.4.330.0030.00315.03
7.4.320.0030.00316.49
7.4.300.0000.00716.57
7.4.290.0000.00816.39
7.4.280.0000.00716.56
7.4.270.0040.00416.48
7.4.260.0030.00316.44
7.4.250.0040.00416.54
7.4.240.0030.00416.59
7.4.230.0080.00016.30
7.4.220.0070.01816.61
7.4.210.0030.01216.40
7.4.200.0070.00016.49
7.4.160.0100.01016.26
7.4.150.0100.00717.40
7.4.140.0110.00917.86
7.4.130.0120.00616.42
7.4.120.0090.00916.46
7.4.110.0140.00316.41
7.4.100.0110.00616.61
7.4.90.0130.00616.46
7.4.80.0160.00618.80
7.4.70.0090.01216.43
7.4.60.0060.01016.45
7.4.50.0040.00416.55
7.4.40.0120.00516.61
7.4.30.0030.01916.47
7.4.00.0060.00614.93
7.3.330.0000.00513.09
7.3.320.0050.00013.07
7.3.310.0000.00716.10
7.3.300.0070.00016.24
7.3.290.0060.00916.20
7.3.280.0120.00916.18
7.3.270.0190.00617.40
7.3.260.0110.00716.31
7.3.250.0140.00316.36
7.3.240.0070.01016.54
7.3.230.0100.00716.47
7.3.210.0060.01216.31
7.3.200.0120.00619.39
7.3.190.0080.01416.22
7.3.180.0160.00616.29
7.3.170.0040.01216.56
7.3.160.0030.01616.39
7.2.330.0040.01416.55
7.2.320.0110.00616.32
7.2.310.0140.00416.48
7.2.300.0060.00916.66
7.2.290.0130.00316.57
7.2.00.0030.00919.41
7.1.100.0060.00617.94
7.1.70.0030.00616.97
7.1.60.0160.01019.32
7.1.50.0120.00916.51
7.1.00.0070.07322.40
7.0.200.0030.00616.61
7.0.140.0000.07722.01
7.0.60.0030.07719.98
7.0.50.0070.06718.02
7.0.40.0030.05320.26
7.0.30.0130.04720.09
7.0.20.0400.07020.36
7.0.10.0100.06720.19
7.0.00.0200.06320.25
5.6.280.0070.07320.92
5.6.210.0030.08720.64
5.6.200.0100.08318.17
5.6.190.0130.06720.39
5.6.180.3670.04020.57
5.6.170.0370.06020.54
5.6.160.0030.04320.59
5.6.150.0030.08718.30
5.6.140.0030.04018.18
5.6.130.0130.05718.18
5.6.120.0070.04321.04
5.6.110.0070.08321.15
5.6.100.0000.04721.04
5.6.90.0030.05721.00
5.6.80.0100.05320.40
5.6.70.4470.04020.38
5.5.350.0030.08020.35
5.5.340.0130.06717.95
5.5.330.0070.08720.26
5.5.320.0270.03020.22
5.5.310.0200.06020.37
5.5.300.0130.07717.96
5.5.290.0100.07318.05
5.5.280.0030.04320.78
5.5.270.0100.05320.78
5.5.260.0130.04020.89
5.5.250.0030.04320.68
5.5.240.0030.07720.20
5.4.450.1030.04319.40
5.4.440.0900.06019.20
5.4.430.0830.06019.16
5.4.420.0900.06319.16
5.4.410.0770.05019.32
5.4.400.0870.05319.30
5.4.390.0800.06019.11
5.4.380.0270.05718.52
5.4.370.0370.07018.56
5.4.360.0270.05718.84
5.4.350.0400.05718.64
5.4.340.0570.06018.62
5.4.320.0060.03812.52
5.4.310.0070.03612.52
5.4.300.0050.04312.52
5.4.290.0080.04612.52
5.4.280.0050.04212.41
5.4.270.0050.03612.41
5.4.260.0090.03512.41
5.4.250.0050.03812.42
5.4.240.0050.03712.41
5.4.230.0060.03612.40
5.4.220.0060.03512.41
5.4.210.0040.03612.41
5.4.200.0050.03812.40
5.4.190.0100.03112.40
5.4.180.0050.03612.40
5.4.170.0050.03612.41
5.4.160.0040.03712.41
5.4.150.0060.03612.41
5.4.140.0060.03612.09
5.4.130.0050.03512.07
5.4.120.0070.03412.04
5.4.110.0090.03412.03
5.4.100.0080.03612.03
5.4.90.0050.03612.03
5.4.80.0040.03812.04
5.4.70.0040.03612.03
5.4.60.0030.03612.03
5.4.50.0090.03712.03
5.4.40.0120.03312.02
5.4.30.0070.03712.01
5.4.20.0100.03812.00
5.4.10.0080.03212.01
5.4.00.0050.03711.50
5.3.290.0060.03912.80
5.3.280.0080.03512.71
5.3.270.0020.04212.72
5.3.260.0050.03912.72
5.3.250.0050.04412.72
5.3.240.0070.03512.72
5.3.230.0090.04112.71
5.3.220.0070.03812.68
5.3.210.0100.04312.68
5.3.200.0080.03812.68
5.3.190.0040.03912.68
5.3.180.0030.04012.67
5.3.170.0080.03912.67
5.3.160.0070.04512.68
5.3.150.0070.04212.68
5.3.140.0070.03912.66
5.3.130.0070.03612.66
5.3.120.0050.04012.66
5.3.110.0050.04112.66
5.3.100.0040.03812.12
5.3.90.0050.03712.08
5.3.80.0040.03712.07
5.3.70.0070.03412.07
5.3.60.0070.03412.06
5.3.50.0060.04412.00
5.3.40.0070.03312.00
5.3.30.0070.03611.95
5.3.20.0090.04111.73
5.3.10.0080.04111.70
5.3.00.0070.03411.68
5.2.170.0020.0329.18
5.2.160.0030.0309.19
5.2.150.0050.0369.18
5.2.140.0070.0359.18
5.2.130.0050.0329.14
5.2.120.0040.0369.14
5.2.110.0040.0299.15
5.2.100.0030.0309.14
5.2.90.0030.0309.15
5.2.80.0050.0349.14
5.2.70.0030.0319.14
5.2.60.0080.0329.09
5.2.50.0040.0309.07
5.2.40.0020.0309.04
5.2.30.0010.0329.02
5.2.20.0050.0279.01
5.2.10.0080.0318.93
5.2.00.0070.0278.79
5.1.60.0040.0258.07
5.1.50.0030.0298.07
5.1.40.0050.0278.05
5.1.30.0030.0268.40
5.1.20.0020.0298.42
5.1.10.0030.0288.14
5.1.00.0100.0298.14
5.0.50.0030.0206.63
5.0.40.0010.0216.48
5.0.30.0020.0326.30
5.0.20.0060.0196.26
5.0.10.0030.0226.24
5.0.00.0030.0316.23
4.4.90.0030.0154.78
4.4.80.0030.0154.75
4.4.70.0040.0144.75
4.4.60.0030.0154.76
4.4.50.0020.0164.77
4.4.40.0020.0254.71
4.4.30.0020.0164.75
4.4.20.0050.0124.85
4.4.10.0030.0154.85
4.4.00.0030.0324.76
4.3.110.0030.0214.67
4.3.100.0040.0154.66
4.3.90.0010.0164.63
4.3.80.0050.0294.59
4.3.70.0030.0144.63
4.3.60.0020.0174.63
4.3.50.0030.0144.63
4.3.40.0010.0304.54
4.3.30.0020.0223.29
4.3.20.0020.0203.27
4.3.10.0020.0163.22
4.3.00.0030.04016.39

preferences:
45.5 ms | 401 KiB | 5 Q