3v4l.org

run code in 300+ PHP versions simultaneously
<?php error_reporting(E_ALL); ini_set('display_errors', 1); 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) { $commentDocReader = new commentDocReader(); $commentDocReader->setClass(__CLASS__); $hints = $commentDocReader->getPropertyHintType($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.0040.01518.81
8.3.50.0110.01118.26
8.3.40.0070.00718.96
8.3.30.0100.01019.08
8.3.20.0070.00020.33
8.3.10.0030.00520.61
8.3.00.0090.00019.38
8.2.180.0120.00316.75
8.2.170.0070.00722.96
8.2.160.0140.00020.39
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0070.00022.23
8.2.110.0060.00322.20
8.2.100.0070.00320.35
8.2.90.0040.00419.28
8.2.80.0030.00517.97
8.2.70.0030.00517.63
8.2.60.0040.00417.93
8.2.50.0030.00518.07
8.2.40.0050.00318.06
8.2.30.0050.00219.29
8.2.20.0080.00017.91
8.2.10.0030.00618.21
8.2.00.0000.00817.89
8.1.280.0130.01025.92
8.1.270.0050.00323.71
8.1.260.0050.00226.35
8.1.250.0040.00428.09
8.1.240.0030.00622.09
8.1.230.0080.00419.01
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0030.00717.35
8.1.190.0080.00017.35
8.1.180.0000.00818.10
8.1.170.0000.00818.52
8.1.160.0040.00422.01
8.1.150.0080.00019.05
8.1.140.0000.00717.50
8.1.130.0000.00717.92
8.1.120.0080.00017.54
8.1.110.0000.00817.47
8.1.100.0040.00417.48
8.1.90.0000.00717.37
8.1.80.0070.00017.52
8.1.70.0000.00717.46
8.1.60.0030.00617.62
8.1.50.0030.00617.56
8.1.40.0030.00617.39
8.1.30.0040.00417.68
8.1.20.0000.00917.52
8.1.10.0000.00817.62
8.1.00.0040.00417.57
8.0.300.0070.00018.77
8.0.290.0090.00016.75
8.0.280.0070.00018.50
8.0.270.0000.00717.30
8.0.260.0070.00017.25
8.0.250.0000.00717.07
8.0.240.0000.00717.01
8.0.230.0050.00217.05
8.0.220.0000.00716.93
8.0.210.0030.00416.86
8.0.200.0060.00017.06
8.0.190.0020.00517.05
8.0.180.0000.00716.90
8.0.170.0000.00816.91
8.0.160.0040.00416.87
8.0.150.0030.00516.95
8.0.140.0040.00416.96
8.0.130.0090.00013.38
8.0.120.0080.00017.02
8.0.110.0070.00017.02
8.0.100.0040.00416.86
8.0.90.0000.00716.89
8.0.80.0030.01316.98
8.0.70.0000.00816.99
8.0.60.0040.00416.89
8.0.50.0000.00917.03
8.0.30.0120.00816.94
8.0.20.0090.00917.40
8.0.10.0040.00417.09
8.0.00.0090.01117.05
7.4.330.0000.00515.00
7.4.320.0040.00416.53
7.4.300.0030.00316.48
7.4.290.0000.00716.54
7.4.280.0070.00016.43
7.4.270.0030.00416.55
7.4.260.0030.00316.53
7.4.250.0040.00416.53
7.4.240.0000.00716.45
7.4.230.0050.00316.45
7.4.220.0100.01616.52
7.4.210.0120.00316.67
7.4.200.0030.00316.38
7.4.160.0160.01016.62
7.4.150.0170.00317.40
7.4.140.0070.01017.86
7.4.130.0020.01516.53
7.4.120.0100.00816.56
7.4.110.0000.01716.65
7.4.100.0100.01016.68
7.4.90.0080.01516.62
7.4.80.0070.01018.80
7.4.70.0120.00616.34
7.4.60.0090.00616.66
7.4.50.0040.00416.22
7.4.40.0110.01116.54
7.4.30.0030.01616.67
7.4.00.0100.00714.98
7.3.330.0030.00313.46
7.3.320.0030.00313.34
7.3.310.0000.00716.36
7.3.300.0070.00016.57
7.3.290.0060.00916.38
7.3.280.0080.00816.44
7.3.270.0070.01417.40
7.3.260.0210.00416.43
7.3.250.0070.01016.58
7.3.240.0150.00316.56
7.3.230.0070.01016.46
7.3.210.0040.01216.28
7.3.200.0160.00719.39
7.3.190.0130.00616.63
7.3.180.0270.03016.48
7.3.170.0060.01216.35
7.3.160.0130.00316.49
7.2.330.0090.00916.88
7.2.320.0090.00916.79
7.2.310.0100.00716.72
7.2.300.0100.00616.47
7.2.290.0160.00016.90
7.2.60.0110.00316.94
7.2.00.0070.00719.57
7.1.200.0040.00715.95
7.1.100.0030.00918.19
7.1.70.0060.00317.01
7.1.60.0100.01619.32
7.1.50.0070.01316.80
7.1.00.0070.07022.54
7.0.200.0000.00916.54
7.0.140.0200.05721.95
7.0.60.0100.08020.00
7.0.50.0000.06717.94
7.0.40.0030.04320.02
7.0.30.0270.08020.30
7.0.20.0300.06320.18
7.0.10.0330.04720.25
7.0.00.0130.08020.16
5.6.280.0030.07721.11
5.6.210.0030.05720.57
5.6.200.0130.07718.23
5.6.190.0070.08720.39
5.6.180.0230.05720.45
5.6.170.0270.05320.45
5.6.160.0230.06720.71
5.6.150.0070.04318.25
5.6.140.0070.03718.24
5.6.130.0000.06018.21
5.6.120.0100.08021.14
5.6.110.0100.09020.98
5.6.100.0200.06020.91
5.6.90.0070.04721.05
5.6.80.0030.07720.55
5.6.70.3870.03020.30
5.5.350.0200.08020.46
5.5.340.0130.03718.05
5.5.330.0200.07320.32
5.5.320.0400.05020.24
5.5.310.0100.04720.35
5.5.300.0100.05317.98
5.5.290.0170.07017.96
5.5.280.0070.04321.00
5.5.270.0070.05320.76
5.5.260.0030.04720.82
5.5.250.0230.06020.57
5.5.240.0270.07320.18
5.4.450.0200.04019.52
5.4.440.0570.06319.55
5.4.430.0930.05319.60
5.4.420.0400.06719.60
5.4.410.0870.05719.26
5.4.400.0930.05019.12
5.4.390.0900.06019.24
5.4.380.0400.06018.50
5.4.370.0430.04318.50
5.4.360.0430.04318.76
5.4.350.0370.05718.86
5.4.340.0400.05018.71
5.4.320.0100.03512.52
5.4.310.0070.03612.52
5.4.300.0100.03112.52
5.4.290.0090.04112.52
5.4.280.0040.03712.41
5.4.270.0080.03912.41
5.4.260.0050.04312.41
5.4.250.0030.03912.42
5.4.240.0050.03712.41
5.4.230.0020.04112.41
5.4.220.0090.03212.41
5.4.210.0030.03712.40
5.4.200.0070.04112.40
5.4.190.0080.04412.41
5.4.180.0080.03712.41
5.4.170.0100.03212.41
5.4.160.0070.03412.41
5.4.150.0040.03712.40
5.4.140.0030.03812.09
5.4.130.0030.03812.08
5.4.120.0050.03512.04
5.4.110.0050.03612.04
5.4.100.0030.04312.03
5.4.90.0030.03912.03
5.4.80.0060.03512.03
5.4.70.0060.03612.02
5.4.60.0070.03212.03
5.4.50.0060.04212.03
5.4.40.0070.03412.02
5.4.30.0070.03312.02
5.4.20.0030.04212.02
5.4.10.0060.03912.01
5.4.00.0050.04511.50
5.3.290.0060.03812.80
5.3.280.0070.03712.71
5.3.270.0050.04012.72
5.3.260.0030.04112.72
5.3.250.0110.03812.71
5.3.240.0060.03612.72
5.3.230.0060.04212.71
5.3.220.0040.03812.68
5.3.210.0080.03612.68
5.3.200.0030.03812.68
5.3.190.0050.03812.68
5.3.180.0030.03812.67
5.3.170.0040.03612.67
5.3.160.0080.03312.67
5.3.150.0070.03512.68
5.3.140.0060.03512.66
5.3.130.0040.03912.66
5.3.120.0030.04412.66
5.3.110.0030.04112.66
5.3.100.0030.03912.12
5.3.90.0040.03912.09
5.3.80.0060.03512.07
5.3.70.0090.03812.07
5.3.60.0070.03912.06
5.3.50.0040.03812.00
5.3.40.0060.03512.00
5.3.30.0070.03511.95
5.3.20.0050.03511.73
5.3.10.0030.03611.70
5.3.00.0060.03611.68
5.2.170.0050.0339.19
5.2.160.0060.0289.19
5.2.150.0060.0289.18
5.2.140.0070.0339.18
5.2.130.0030.0299.14
5.2.120.0020.0299.14
5.2.110.0070.0309.15
5.2.100.0030.0299.14
5.2.90.0040.0299.14
5.2.80.0040.0309.14
5.2.70.0040.0309.14
5.2.60.0040.0309.09
5.2.50.0050.0289.07
5.2.40.0070.0329.04
5.2.30.0050.0299.02
5.2.20.0040.0299.00
5.2.10.0070.0258.93
5.2.00.0060.0268.79
5.1.60.0040.0298.08
5.1.50.0050.0248.07
5.1.40.0020.0348.05
5.1.30.0020.0348.40
5.1.20.0060.0298.42
5.1.10.0050.0238.15
5.1.00.0050.0238.15
5.0.50.0040.0196.62
5.0.40.0040.0276.48
5.0.30.0040.0316.29
5.0.20.0040.0266.26
5.0.10.0060.0236.24
5.0.00.0030.0346.23
4.4.90.0040.0164.78
4.4.80.0040.0234.75
4.4.70.0020.0224.75
4.4.60.0020.0164.75
4.4.50.0020.0154.77
4.4.40.0060.0244.71
4.4.30.0030.0154.76
4.4.20.0030.0154.85
4.4.10.0040.0144.84
4.4.00.0040.0274.76
4.3.110.0040.0144.67
4.3.100.0010.0174.66
4.3.90.0040.0144.63
4.3.80.0060.0244.59
4.3.70.0020.0144.63
4.3.60.0060.0114.62
4.3.50.0050.0154.63
4.3.40.0010.0284.54
4.3.30.0010.0223.29
4.3.20.0020.0213.27
4.3.10.0010.0173.22
4.3.00.0230.03016.39

preferences:
47.09 ms | 400 KiB | 5 Q