3v4l.org

run code in 300+ PHP versions simultaneously
<?phperror_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.40.0120.00318.89
8.3.30.0070.00719.02
8.3.20.0070.00020.16
8.3.10.0040.00420.59
8.3.00.0080.00019.04
8.2.170.0070.00722.96
8.2.160.0100.00720.38
8.2.150.0080.00024.18
8.2.140.0050.00324.66
8.2.130.0080.00026.16
8.2.120.0050.00222.20
8.2.110.0000.00821.95
8.2.100.0080.00320.39
8.2.90.0040.00419.22
8.2.80.0000.00817.97
8.2.70.0000.00817.36
8.2.60.0030.00917.93
8.2.50.0000.00818.07
8.2.40.0000.00918.19
8.2.30.0000.00719.25
8.2.20.0050.00217.64
8.2.10.0000.00717.83
8.2.00.0050.00217.55
8.1.270.0020.00523.96
8.1.260.0000.00826.35
8.1.250.0000.00728.09
8.1.240.0070.00322.09
8.1.230.0070.00419.09
8.1.220.0000.00817.74
8.1.210.0070.00018.77
8.1.200.0000.00817.22
8.1.190.0040.00417.23
8.1.180.0040.00418.10
8.1.170.0030.00518.52
8.1.160.0060.00321.99
8.1.150.0000.00818.69
8.1.140.0000.00717.27
8.1.130.0000.00717.73
8.1.120.0000.00717.36
8.1.110.0080.00017.35
8.1.100.0000.00717.28
8.1.90.0000.00717.26
8.1.80.0040.00317.29
8.1.70.0030.00317.18
8.1.60.0000.01017.34
8.1.50.0060.00317.40
8.1.40.0040.00417.37
8.1.30.0040.00417.44
8.1.20.0000.00817.56
8.1.10.0040.00417.38
8.1.00.0000.00817.30
8.0.300.0000.00718.77
8.0.290.0040.00416.63
8.0.280.0000.00718.37
8.0.270.0000.00717.20
8.0.260.0030.00317.11
8.0.250.0000.00716.84
8.0.240.0050.00316.71
8.0.230.0030.00316.87
8.0.220.0070.00016.77
8.0.210.0030.00316.64
8.0.200.0000.00716.75
8.0.190.0070.00016.87
8.0.180.0000.00716.78
8.0.170.0030.00516.82
8.0.160.0030.00316.73
8.0.150.0070.00016.59
8.0.140.0000.00816.75
8.0.130.0030.00513.39
8.0.120.0040.00416.73
8.0.110.0000.00716.76
8.0.100.0000.00716.65
8.0.90.0070.00016.65
8.0.80.0140.00716.76
8.0.70.0050.00316.72
8.0.60.0030.00316.73
8.0.50.0030.00616.88
8.0.30.0140.00416.92
8.0.20.0030.01617.40
8.0.10.0000.00716.91
8.0.00.0080.01116.43
7.4.330.0060.00015.09
7.4.320.0030.00316.48
7.4.300.0000.00716.38
7.4.290.0000.00616.38
7.4.280.0080.00016.50
7.4.270.0070.00016.49
7.4.260.0030.00316.25
7.4.250.0040.00416.36
7.4.240.0030.00316.43
7.4.230.0000.00716.27
7.4.220.0120.01316.57
7.4.210.0130.00616.38
7.4.200.0040.00416.21
7.4.160.0110.01116.41
7.4.150.0090.00917.40
7.4.140.0110.00617.86
7.4.130.0090.00816.37
7.4.120.0060.01116.40
7.4.110.0080.01116.56
7.4.100.0100.00716.36
7.4.90.0160.00616.46
7.4.80.0120.00918.80
7.4.70.0130.00916.57
7.4.60.0120.00316.38
7.4.50.0040.00416.38
7.4.40.0180.00416.50
7.4.30.0070.01316.50
7.3.330.0060.00013.09
7.3.320.0060.00013.06
7.3.310.0030.00316.06
7.3.300.0000.00716.20
7.3.290.0050.01016.08
7.3.280.0070.00916.13
7.3.270.0170.00617.40
7.3.260.0120.01216.16
7.3.250.0120.00516.29
7.3.240.0120.00616.46
7.3.230.0130.00316.39
7.3.210.0080.00816.30
7.3.200.0110.01119.39
7.3.190.0140.00316.15
7.3.180.0220.02916.16
7.3.170.0030.01316.47
7.3.160.0000.01616.29
7.2.330.0140.00316.29
7.2.320.0080.00916.63
7.2.310.0120.00616.64
7.2.300.0100.01016.29
7.2.290.0040.01216.59
5.4.320.0070.03712.46
5.4.310.0070.03912.45
5.4.300.0060.03912.46
5.4.290.0070.03912.46
5.4.280.0070.03712.35
5.4.270.0070.04312.35
5.4.260.0080.04612.36
5.4.250.0110.03812.36
5.4.240.0050.03812.36
5.4.230.0060.03912.34
5.4.220.0030.04512.34
5.4.210.0090.03412.35
5.4.200.0070.05312.35
5.4.190.0110.03712.34
5.4.180.0040.04212.34
5.4.170.0070.04012.35
5.4.160.0050.04612.35
5.4.150.0090.03812.34
5.4.140.0080.03412.03
5.4.130.0060.04312.02
5.4.120.0070.03611.97
5.4.110.0060.04511.97
5.4.100.0060.03611.97
5.4.90.0070.03711.97
5.4.80.0090.03611.97
5.4.70.0100.03711.97
5.4.60.0050.03611.96
5.4.50.0060.03611.96
5.4.40.0050.03511.96
5.4.30.0050.04011.95
5.4.20.0030.04711.96
5.4.10.0080.03811.95
5.4.00.0040.03711.44

preferences:
31.76 ms | 400 KiB | 5 Q