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.0030.01318.43
8.3.50.0060.01618.08
8.3.40.0090.00619.00
8.3.30.0120.00919.00
8.3.20.0000.00820.04
8.3.10.0030.00520.76
8.3.00.0060.00319.75
8.2.180.0060.00916.63
8.2.170.0040.01122.96
8.2.160.0100.00320.46
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0000.00722.37
8.2.110.0060.00322.10
8.2.100.0110.00020.54
8.2.90.0040.00419.39
8.2.80.0030.00617.97
8.2.70.0030.00617.75
8.2.60.0060.00317.93
8.2.50.0040.00418.07
8.2.40.0050.00318.28
8.2.30.0000.00819.17
8.2.20.0050.00317.87
8.2.10.0000.00718.25
8.2.00.0000.00818.00
8.1.280.0040.01425.92
8.1.270.0060.00322.32
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0060.00323.83
8.1.230.0070.00318.97
8.1.220.0050.00317.77
8.1.210.0000.00818.77
8.1.200.0030.00717.60
8.1.190.0030.00517.38
8.1.180.0040.00418.10
8.1.170.0040.00418.90
8.1.160.0000.00722.14
8.1.150.0040.00419.04
8.1.140.0060.00317.64
8.1.130.0050.00317.86
8.1.120.0040.00417.51
8.1.110.0080.00017.68
8.1.100.0000.00717.63
8.1.90.0040.00417.62
8.1.80.0050.00217.70
8.1.70.0030.00317.56
8.1.60.0060.00317.78
8.1.50.0050.00517.68
8.1.40.0080.00017.69
8.1.30.0040.00417.77
8.1.20.0040.00417.73
8.1.10.0090.00017.77
8.1.00.0000.00817.74
8.0.300.0040.00418.77
8.0.290.0030.00517.00
8.0.280.0070.00018.38
8.0.270.0000.00717.31
8.0.260.0000.00717.36
8.0.250.0030.00317.16
8.0.240.0030.00517.00
8.0.230.0070.00017.13
8.0.220.0000.00717.07
8.0.210.0000.00717.07
8.0.200.0070.00017.13
8.0.190.0040.00417.09
8.0.180.0040.00417.07
8.0.170.0050.00316.96
8.0.160.0070.00017.01
8.0.150.0070.00017.00
8.0.140.0070.00016.85
8.0.130.0040.00413.52
8.0.120.0050.00317.04
8.0.110.0020.00517.03
8.0.100.0000.00717.09
8.0.90.0000.00717.03
8.0.80.0120.00617.02
8.0.70.0030.00516.89
8.0.60.0070.00016.96
8.0.50.0060.00317.06
8.0.30.0130.00717.34
8.0.20.0090.01017.48
8.0.10.0040.00417.15
8.0.00.0080.01017.00
7.4.330.0030.00215.10
7.4.320.0000.00616.75
7.4.300.0040.00416.65
7.4.290.0000.00716.70
7.4.280.0070.00016.82
7.4.270.0030.00316.64
7.4.260.0030.00516.75
7.4.250.0040.00416.61
7.4.240.0050.00216.77
7.4.230.0000.00716.91
7.4.220.0130.00616.80
7.4.210.0080.00916.76
7.4.200.0030.00316.75
7.4.160.0090.00916.82
7.4.150.0100.01017.40
7.4.140.0090.00817.86
7.4.130.0060.01116.71
7.4.120.0060.01516.70
7.4.110.0190.00016.64
7.4.100.0120.00916.79
7.4.90.0060.01216.75
7.4.80.0060.01218.80
7.4.70.0090.01416.75
7.4.60.0130.00316.80
7.4.50.0000.00816.83
7.4.40.0160.00316.73
7.4.30.0150.00316.66
7.4.00.0040.01115.30
7.3.330.0000.00513.56
7.3.320.0030.00313.56
7.3.310.0040.00416.50
7.3.300.0020.00516.55
7.3.290.0030.01716.56
7.3.280.0090.00916.55
7.3.270.0060.01317.40
7.3.260.0140.00716.46
7.3.250.0100.00816.89
7.3.240.0090.00916.85
7.3.230.0080.00816.57
7.3.210.0120.00616.77
7.3.200.0070.01619.39
7.3.190.0180.00616.79
7.3.180.0060.01216.72
7.3.170.0050.01316.73
7.3.160.0100.00616.54
7.2.330.0120.00616.93
7.2.320.0100.01016.84
7.2.310.0090.00917.08
7.2.300.0070.01017.09
7.2.290.0070.01116.93
7.2.60.0140.00317.07
7.1.200.0250.01215.79
7.1.70.0000.01017.10
7.1.60.0090.01519.32
7.1.50.0100.01017.14
7.1.00.0030.07722.35
7.0.200.0000.00816.90
7.0.140.0030.07721.98
7.0.70.3930.03719.98
7.0.60.0170.06720.04
7.0.50.0030.07017.93
7.0.40.0070.08020.13
7.0.30.0570.07020.25
7.0.20.0330.07720.22
7.0.10.0330.07320.08
7.0.00.0100.07320.17
5.6.280.0000.08021.02
5.6.210.0000.05320.77
5.6.200.0030.04018.16
5.6.190.0070.08720.41
5.6.180.0070.08320.39
5.6.170.0430.07320.52
5.6.160.0200.07020.50
5.6.150.0100.08318.17
5.6.140.0070.06318.20
5.6.130.0100.07318.27
5.6.120.0130.07721.13
5.6.110.0170.07321.03
5.6.100.0100.03721.13
5.6.90.0070.08721.05
5.6.80.0100.07720.43
5.6.70.0270.04720.41
5.5.350.0000.03320.41
5.5.340.0070.08718.09
5.5.330.0070.04320.29
5.5.320.0100.08020.22
5.5.310.0200.07020.26
5.5.300.0100.08317.96
5.5.290.0070.08018.07
5.5.280.0030.08720.91
5.5.270.0100.08720.98
5.5.260.0070.08720.78
5.5.250.0130.06720.48
5.5.240.0170.06720.26
5.4.450.0900.03719.41
5.4.440.0970.07719.57
5.4.430.0100.05719.45
5.4.420.0970.05319.53
5.4.410.0070.07019.45
5.4.400.0730.05319.23
5.4.390.0900.06019.22
5.4.380.0200.07718.79
5.4.370.0300.05718.61
5.4.360.0370.04318.77
5.4.350.0330.06018.80
5.4.340.0670.06018.63
5.4.320.0070.03712.52
5.4.310.0050.04312.52
5.4.300.0060.03612.52
5.4.290.0050.04712.52
5.4.280.0080.03212.41
5.4.270.0050.03812.41
5.4.260.0100.03912.41
5.4.250.0090.04212.42
5.4.240.0090.04012.41
5.4.230.0070.04612.41
5.4.220.0090.03712.41
5.4.210.0040.04112.41
5.4.200.0060.04112.41
5.4.190.0060.03412.41
5.4.180.0080.03212.40
5.4.170.0060.03512.41
5.4.160.0040.03612.41
5.4.150.0030.04612.40
5.4.140.0050.03712.09
5.4.130.0040.03612.08
5.4.120.0080.03212.04
5.4.110.0050.03512.03
5.4.100.0030.03912.03
5.4.90.0040.04212.03
5.4.80.0060.04212.04
5.4.70.0060.03512.03
5.4.60.0050.03612.03
5.4.50.0040.03812.03
5.4.40.0080.03212.02
5.4.30.0060.03512.01
5.4.20.0090.03412.01
5.4.10.0050.03812.01
5.4.00.0100.03111.50
5.3.290.0070.03712.80
5.3.280.0120.03812.71
5.3.270.0080.04012.72
5.3.260.0080.03612.72
5.3.250.0050.03712.72
5.3.240.0030.03912.72
5.3.230.0080.04112.71
5.3.220.0050.04012.68
5.3.210.0060.03812.68
5.3.200.0100.03612.68
5.3.190.0040.04212.68
5.3.180.0080.03312.67
5.3.170.0090.03912.67
5.3.160.0080.03812.67
5.3.150.0080.03812.67
5.3.140.0060.03712.66
5.3.130.0070.03712.66
5.3.120.0030.04112.66
5.3.110.0060.03712.66
5.3.100.0070.04312.12
5.3.90.0050.03612.09
5.3.80.0030.03912.08
5.3.70.0070.04112.07
5.3.60.0040.04212.07
5.3.50.0060.03412.00
5.3.40.0080.04012.00
5.3.30.0060.03311.95
5.3.20.0070.04111.73
5.3.10.0030.03611.70
5.3.00.0030.04011.68
5.2.170.0040.0309.19
5.2.160.0030.0299.19
5.2.150.0020.0329.19
5.2.140.0060.0329.18
5.2.130.0040.0299.14
5.2.120.0050.0319.14
5.2.110.0040.0359.15
5.2.100.0030.0309.14
5.2.90.0010.0329.15
5.2.80.0050.0329.14
5.2.70.0050.0299.14
5.2.60.0090.0289.09
5.2.50.0040.0309.07
5.2.40.0070.0319.04
5.2.30.0030.0369.02
5.2.20.0060.0319.01
5.2.10.0040.0288.93
5.2.00.0050.0318.79
5.1.60.0060.0238.07
5.1.50.0040.0288.07
5.1.40.0040.0288.05
5.1.30.0080.0268.40
5.1.20.0030.0318.42
5.1.10.0030.0308.14
5.1.00.0060.0278.14
5.0.50.0000.0236.63
5.0.40.0030.0286.48
5.0.30.0030.0356.30
5.0.20.0020.0206.27
5.0.10.0060.0246.25
5.0.00.0060.0306.23
4.4.90.0030.0244.78
4.4.80.0050.0164.75
4.4.70.0020.0164.76
4.4.60.0020.0164.75
4.4.50.0030.0154.77
4.4.40.0020.0274.71
4.4.30.0030.0154.76
4.4.20.0010.0174.85
4.4.10.0020.0164.85
4.4.00.0020.0264.75
4.3.110.0030.0154.67
4.3.100.0010.0164.67
4.3.90.0010.0154.63
4.3.80.0020.0274.58
4.3.70.0050.0164.63
4.3.60.0010.0154.62
4.3.50.0030.0214.63
4.3.40.0000.0254.54
4.3.30.0010.0163.29
4.3.20.0040.0133.26
4.3.10.0030.0143.22
4.3.00.0170.01016.39

preferences:
72.07 ms | 400 KiB | 5 Q