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($MyClass)->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.0190.00018.68
8.3.50.0100.01122.10
8.3.40.0080.00818.99
8.3.30.0060.00919.17
8.3.20.0090.00020.16
8.3.10.0040.00420.86
8.3.00.0000.00819.63
8.2.180.0070.00717.00
8.2.170.0110.00422.96
8.2.160.0130.00320.52
8.2.150.0040.00424.18
8.2.140.0080.00024.66
8.2.130.0050.00326.16
8.2.120.0070.00022.18
8.2.110.0030.00622.25
8.2.100.0070.00320.40
8.2.90.0000.00919.04
8.2.80.0030.00517.97
8.2.70.0030.00617.75
8.2.60.0060.00617.93
8.2.50.0040.00418.07
8.2.40.0030.00518.28
8.2.30.0040.00419.21
8.2.20.0000.00817.81
8.2.10.0040.00418.13
8.2.00.0040.00418.02
8.1.280.0100.01025.92
8.1.270.0060.00323.81
8.1.260.0040.00426.35
8.1.250.0050.00228.09
8.1.240.0060.00323.83
8.1.230.0000.01119.05
8.1.220.0030.00517.74
8.1.210.0000.00818.77
8.1.200.0030.00617.48
8.1.190.0030.00517.60
8.1.180.0000.00818.10
8.1.170.0040.00418.69
8.1.160.0000.00821.94
8.1.150.0080.00018.98
8.1.140.0000.00817.56
8.1.130.0040.00417.88
8.1.120.0030.00517.50
8.1.110.0040.00417.62
8.1.100.0040.00417.68
8.1.90.0000.00817.62
8.1.80.0000.00717.55
8.1.70.0070.00017.60
8.1.60.0040.00417.73
8.1.50.0000.00817.66
8.1.40.0090.00017.68
8.1.30.0050.00317.79
8.1.20.0040.00417.84
8.1.10.0040.00417.71
8.1.00.0040.00417.74
8.0.300.0070.00018.77
8.0.290.0080.00016.88
8.0.280.0050.00318.50
8.0.270.0020.00517.25
8.0.260.0030.00317.30
8.0.250.0000.00717.07
8.0.240.0030.00517.03
8.0.230.0030.00317.04
8.0.220.0040.00416.97
8.0.210.0000.00717.09
8.0.200.0030.00317.18
8.0.190.0000.00717.01
8.0.180.0000.00717.02
8.0.170.0000.00816.99
8.0.160.0040.00417.14
8.0.150.0000.00717.01
8.0.140.0000.00717.04
8.0.130.0090.00013.56
8.0.120.0000.00816.95
8.0.110.0030.00517.05
8.0.100.0040.00416.85
8.0.90.0070.00017.00
8.0.80.0100.00717.13
8.0.70.0040.00416.87
8.0.60.0040.00417.03
8.0.50.0030.00616.86
8.0.30.0120.00817.12
8.0.20.0090.01017.43
8.0.10.0000.00717.21
8.0.00.0080.00916.92
7.4.330.0020.00215.00
7.4.320.0030.00316.65
7.4.300.0000.00716.84
7.4.290.0070.00016.68
7.4.280.0000.00716.73
7.4.270.0030.00316.66
7.4.260.0080.00016.76
7.4.250.0030.00616.76
7.4.240.0040.00316.86
7.4.230.0000.00716.93
7.4.220.0180.00916.67
7.4.210.0110.00316.92
7.4.200.0000.00716.83
7.4.160.0090.01216.73
7.4.150.0100.01417.40
7.4.140.0110.00817.86
7.4.130.0090.00916.76
7.4.120.0100.00816.66
7.4.110.0110.00716.90
7.4.100.0090.00916.80
7.4.90.0150.00616.97
7.4.80.0030.01418.80
7.4.70.0050.01216.70
7.4.60.0080.01516.78
7.4.50.0030.00616.72
7.4.40.0120.00616.58
7.4.30.0070.01016.61
7.4.00.0060.01215.26
7.3.330.0000.00513.50
7.3.320.0030.00313.41
7.3.310.0050.00316.55
7.3.300.0070.00016.43
7.3.290.0130.00316.56
7.3.280.0060.01416.51
7.3.270.0120.01217.40
7.3.260.0140.01116.48
7.3.250.0090.00816.66
7.3.240.0090.00916.86
7.3.230.0130.00316.52
7.3.210.0180.00616.78
7.3.200.0090.00919.39
7.3.190.0080.00916.68
7.3.180.0140.02916.49
7.3.170.0140.00316.58
7.3.160.0080.00816.74
7.3.120.0100.01014.69
7.3.110.0100.00715.13
7.3.100.0100.00314.91
7.3.90.0040.01115.18
7.3.80.0030.01014.98
7.3.70.0070.01015.05
7.3.60.0040.00815.18
7.3.50.0070.00715.10
7.3.40.0060.00614.85
7.3.30.0100.00615.10
7.3.20.0030.01316.88
7.3.10.0030.00616.77
7.3.00.0030.00616.88
7.2.330.0090.00916.92
7.2.320.0100.00716.89
7.2.310.0080.00816.93
7.2.300.0100.00717.00
7.2.290.0030.01316.96
7.2.250.0100.01015.21
7.2.240.0070.01115.48
7.2.230.0060.00615.43
7.2.220.0030.01015.58
7.2.210.0040.00815.44
7.2.200.0120.00615.38
7.2.190.0040.01115.38
7.2.180.0060.00915.23
7.2.170.0030.01415.47
7.1.330.0080.00816.01
7.1.320.0030.00915.56
7.1.310.0060.00615.78
7.1.300.0090.00615.89
7.1.290.0040.01115.95
7.1.280.0090.00616.10
7.1.270.0030.01416.00
7.1.260.0100.00315.71
7.1.200.0100.00315.82
7.1.100.0040.00718.43
7.1.70.0000.00817.11
7.1.60.0100.01619.32
7.1.50.0000.01817.25
7.1.00.0100.07022.32
7.0.200.0080.00016.91
7.0.140.0100.07022.09
7.0.60.0070.08019.99
7.0.50.0170.04718.00
7.0.40.0130.04320.32
7.0.30.0500.07720.07
7.0.20.0300.08020.09
7.0.10.0070.06720.24
7.0.00.0170.04020.33
5.6.280.0030.09021.04
5.6.210.0030.04020.68
5.6.200.0070.07718.28
5.6.190.0100.06720.77
5.6.180.0500.06720.39
5.6.170.0200.05320.45
5.6.160.0100.04720.55
5.6.150.0100.04018.27
5.6.140.0070.06718.21
5.6.130.0100.04718.16
5.6.120.0000.05020.82
5.6.110.0070.06720.91
5.6.100.0100.07321.06
5.6.90.0070.08321.04
5.6.80.0130.06720.39
5.5.350.0170.07320.43
5.5.340.0070.03317.97
5.5.330.0100.08320.42
5.5.320.0300.06020.30
5.5.310.0230.04020.43
5.5.300.0100.07717.97
5.5.290.0130.07018.08
5.5.280.0000.04320.91
5.5.270.0070.04020.80
5.5.260.0030.07720.67
5.5.250.0130.04720.73
5.5.240.0400.02720.28
5.4.450.0600.04019.57
5.4.440.0900.06019.20
5.4.430.1030.04719.62
5.4.420.0670.06319.47
5.4.410.0700.05719.07
5.4.400.0870.05319.40
5.4.390.0270.05319.27
5.4.380.0470.05018.52
5.4.370.0330.05718.75
5.4.360.0300.05018.49
5.4.350.0170.06018.60
5.4.340.0330.06718.60
5.4.320.0040.03812.52
5.4.310.0040.03812.52
5.4.300.0120.03412.52
5.4.290.0040.03812.51
5.4.280.0090.03712.41
5.4.270.0090.03712.42
5.4.260.0060.04012.41
5.4.250.0060.03912.41
5.4.240.0040.04612.41
5.4.230.0090.04012.41
5.4.220.0070.03412.40
5.4.210.0060.03512.41
5.4.200.0050.03712.41
5.4.190.0080.04412.40
5.4.180.0070.03412.40
5.4.170.0080.03512.41
5.4.160.0080.03612.41
5.4.150.0070.03812.40
5.4.140.0060.04012.09
5.4.130.0060.04412.08
5.4.120.0090.03812.03
5.4.110.0040.04012.03
5.4.100.0040.03612.03
5.4.90.0060.03612.03
5.4.80.0070.04612.04
5.4.70.0040.03712.03
5.4.60.0060.03412.03
5.4.50.0040.03712.03
5.4.40.0030.03712.02
5.4.30.0060.03712.01
5.4.20.0040.03512.01
5.4.10.0050.03412.01
5.4.00.0080.03711.50
5.3.290.0080.03612.80
5.3.280.0060.04512.71
5.3.270.0030.04312.72
5.3.260.0040.03912.72
5.3.250.0070.03412.72
5.3.240.0060.04712.72
5.3.230.0070.04212.71
5.3.220.0090.04612.68
5.3.210.0070.04712.68
5.3.200.0040.03612.68
5.3.190.0080.03712.68
5.3.180.0070.03612.67
5.3.170.0040.03712.67
5.3.160.0030.03812.67
5.3.150.0080.03312.67
5.3.140.0060.03512.66
5.3.130.0060.04012.66
5.3.120.0090.04012.66
5.3.110.0060.04012.66
5.3.100.0070.04412.12
5.3.90.0070.03912.09
5.3.80.0050.03512.08
5.3.70.0050.04312.07
5.3.60.0070.04012.06
5.3.50.0060.03612.00
5.3.40.0060.04112.00
5.3.30.0070.03811.95
5.3.20.0060.03911.73
5.3.10.0080.03211.70
5.3.00.0040.03711.68
5.2.170.0040.0319.18
5.2.160.0050.0339.18
5.2.150.0050.0299.18
5.2.140.0050.0309.18
5.2.130.0060.0349.14
5.2.120.0060.0279.14
5.2.110.0040.0379.15
5.2.100.0050.0289.15
5.2.90.0080.0369.14
5.2.80.0040.0329.14
5.2.70.0050.0339.14
5.2.60.0060.0349.10
5.2.50.0050.0299.06
5.2.40.0100.0289.04
5.2.30.0060.0389.02
5.2.20.0050.0339.01
5.2.10.0050.0328.93
5.2.00.0060.0318.79
5.1.60.0060.0238.07
5.1.50.0050.0258.06
5.1.40.0040.0258.05
5.1.30.0040.0268.40
5.1.20.0070.0358.42
5.1.10.0040.0268.14
5.1.00.0040.0268.14
5.0.50.0060.0236.62
5.0.40.0040.0216.48
5.0.30.0050.0306.30
5.0.20.0040.0206.26
5.0.10.0030.0216.24
5.0.00.0050.0296.23
4.4.90.0030.0224.78
4.4.80.0030.0184.76
4.4.70.0050.0144.75
4.4.60.0030.0154.75
4.4.50.0050.0164.77
4.4.40.0070.0274.71
4.4.30.0060.0124.76
4.4.20.0040.0154.85
4.4.10.0020.0194.85
4.4.00.0020.0254.76
4.3.110.0010.0174.66
4.3.100.0040.0174.66
4.3.90.0020.0154.64
4.3.80.0040.0234.58
4.3.70.0030.0294.63
4.3.60.0010.0164.62
4.3.50.0030.0174.63
4.3.40.0070.0264.54
4.3.30.0040.0173.29
4.3.20.0000.0173.26
4.3.10.0010.0173.22
4.3.00.0030.02016.39

preferences:
41.81 ms | 401 KiB | 5 Q