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) { $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.40.0040.01119.17
8.3.30.0090.00619.25
8.3.20.0050.00320.16
8.3.10.0080.00020.95
8.3.00.0060.00319.63
8.2.170.0140.00022.96
8.2.160.0100.00720.52
8.2.150.0070.00024.18
8.2.140.0040.00424.66
8.2.130.0070.00026.16
8.2.120.0030.00622.20
8.2.110.0060.00322.33
8.2.100.0090.00320.48
8.2.90.0060.00319.30
8.2.80.0040.00417.97
8.2.70.0090.00017.88
8.2.60.0030.00718.05
8.2.50.0080.00018.07
8.2.40.0000.00818.33
8.2.30.0000.00719.44
8.2.20.0080.00017.93
8.2.10.0040.00418.13
8.2.00.0040.00417.80
8.1.270.0080.00023.75
8.1.260.0050.00326.35
8.1.250.0050.00328.09
8.1.240.0060.00323.96
8.1.230.0070.00419.27
8.1.220.0050.00317.74
8.1.210.0040.00418.77
8.1.200.0060.00317.60
8.1.190.0080.00017.47
8.1.180.0040.00418.10
8.1.170.0030.00618.90
8.1.160.0050.00322.07
8.1.150.0040.00419.01
8.1.140.0070.00017.48
8.1.130.0030.00317.80
8.1.120.0000.00717.55
8.1.110.0000.00817.56
8.1.100.0040.00417.53
8.1.90.0040.00417.64
8.1.80.0000.00817.64
8.1.70.0030.00317.55
8.1.60.0040.00417.77
8.1.50.0030.00617.74
8.1.40.0040.00417.74
8.1.30.0030.00617.70
8.1.20.0080.00017.82
8.1.10.0000.00817.64
8.1.00.0050.00217.66
8.0.300.0060.00318.77
8.0.290.0040.00417.00
8.0.280.0000.00718.51
8.0.270.0070.00017.38
8.0.260.0000.00617.23
8.0.250.0030.00317.16
8.0.240.0080.00017.07
8.0.230.0040.00417.01
8.0.220.0000.00717.06
8.0.210.0070.00017.04
8.0.200.0070.00017.10
8.0.190.0040.00417.06
8.0.180.0080.00017.12
8.0.170.0000.00917.02
8.0.160.0000.00717.07
8.0.150.0070.00017.01
8.0.140.0000.00716.94
8.0.130.0060.00313.55
8.0.120.0080.00016.94
8.0.110.0080.00016.92
8.0.100.0050.00317.08
8.0.90.0040.00416.93
8.0.80.0100.00716.98
8.0.70.0050.00316.95
8.0.60.0000.00816.95
8.0.50.0030.00517.14
8.0.30.0110.00717.42
8.0.20.0120.00717.50
8.0.10.0040.00417.27
8.0.00.0120.00816.84
7.4.330.0000.00515.11
7.4.320.0040.00416.84
7.4.300.0000.00616.74
7.4.290.0000.00716.69
7.4.280.0030.00516.84
7.4.270.0000.00716.83
7.4.260.0030.00316.80
7.4.250.0050.00316.79
7.4.240.0030.00416.85
7.4.230.0040.00416.65
7.4.220.0130.00616.89
7.4.210.0070.01116.72
7.4.200.0030.00416.69
7.4.160.0060.01616.88
7.4.150.0100.01017.40
7.4.140.0060.01117.86
7.4.130.0120.00616.65
7.4.120.0080.01316.83
7.4.110.0060.01116.55
7.4.100.0070.01116.50
7.4.90.0100.01016.83
7.4.80.0110.01118.80
7.4.70.0140.00416.88
7.4.60.0110.00716.77
7.4.50.0030.00616.61
7.4.40.0060.01316.88
7.4.30.0030.01916.77
7.4.00.0090.00615.04
7.3.330.0060.00013.48
7.3.320.0060.00013.34
7.3.310.0070.00016.60
7.3.300.0030.00316.62
7.3.290.0060.00916.60
7.3.280.0090.00616.53
7.3.270.0120.00617.40
7.3.260.0060.01216.75
7.3.250.0080.01016.71
7.3.240.0120.00616.86
7.3.230.0030.01316.67
7.3.210.0240.00016.82
7.3.200.0120.00619.39
7.3.190.0070.01716.89
7.3.180.0140.00416.88
7.3.170.0120.00616.94
7.3.160.0070.01016.50
7.3.120.0110.00714.73
7.3.110.0070.01314.77
7.3.100.0100.01015.05
7.3.90.0090.00315.02
7.3.80.0040.01215.07
7.3.70.0000.01315.03
7.3.60.0000.01514.86
7.3.50.0060.00815.14
7.3.40.0070.00715.04
7.3.30.0100.00715.08
7.3.20.0040.00916.75
7.3.10.0060.00616.92
7.3.00.0040.01116.63
7.2.330.0140.00316.74
7.2.320.0060.01317.04
7.2.310.0070.01016.96
7.2.300.0140.00316.93
7.2.290.0060.00917.05
7.2.250.0130.00715.52
7.2.240.0070.01215.19
7.2.230.0030.01215.18
7.2.220.0100.00615.47
7.2.210.0040.01115.41
7.2.200.0090.00615.29
7.2.190.0000.01315.25
7.2.180.0030.00915.45
7.2.170.0060.01315.06
7.2.160.0060.00615.33
7.2.150.0070.00716.90
7.2.140.0130.00316.97
7.2.130.0030.01317.02
7.2.120.0080.00817.07
7.2.110.0130.00316.98
7.2.100.0110.00317.15
7.2.90.0000.01317.17
7.2.80.0040.01117.23
7.2.70.0030.00617.09
7.2.60.0050.00817.19
7.2.50.0100.01017.04
7.2.40.0060.00917.11
7.2.30.0080.00317.01
7.2.20.0030.00917.16
7.2.10.0030.01317.20
7.2.00.0080.00618.48
7.1.330.0030.01415.99
7.1.320.0090.00616.13
7.1.310.0060.00616.18
7.1.300.0030.01215.86
7.1.290.0100.00015.90
7.1.280.0070.00716.12
7.1.270.0030.00815.90
7.1.260.0040.01115.85
7.1.250.0070.00716.02
7.1.240.0040.00415.94
7.1.230.0060.01215.88
7.1.220.0040.01215.90
7.1.210.0030.00615.97
7.1.200.0080.00516.09
7.1.190.0070.00415.86
7.1.180.0130.00615.71
7.1.170.0040.01116.11
7.1.160.0080.00815.90
7.1.150.0060.00615.78
7.1.140.0000.01416.05
7.1.130.0100.00716.00
7.1.120.0040.00816.08
7.1.110.0090.00615.82
7.1.100.0050.01017.09
7.1.90.0040.00815.58
7.1.80.0150.00015.93
7.1.70.0020.01016.83
7.1.60.0050.01417.59
7.1.50.0100.01016.52
7.1.40.0060.00915.84
7.1.30.0100.00315.94
7.1.20.0030.00715.86
7.1.10.0060.00615.84
7.1.00.0040.04019.21
7.0.330.0000.01115.48
7.0.320.0030.01015.61
7.0.310.0070.00715.39
7.0.300.0060.00615.50
7.0.290.0060.00915.75
7.0.280.0040.00415.73
7.0.270.0060.00815.54
7.0.260.0100.00315.78
7.0.250.0030.00615.49
7.0.240.0030.01315.52
7.0.230.0070.00715.63
7.0.220.0070.00415.54
7.0.210.0080.00015.54
7.0.200.0020.01016.18
7.0.190.0070.00715.70
7.0.180.0030.00715.50
7.0.170.0030.00915.40
7.0.160.0040.00715.64
7.0.150.0030.00615.75
7.0.140.0090.03518.78
7.0.130.0080.00815.69
7.0.120.0030.01015.76
7.0.110.0000.01315.68
7.0.100.0030.01015.50
7.0.90.0030.00715.35
7.0.80.0040.00715.56
7.0.70.0000.01215.61
7.0.60.0180.04117.86
7.0.50.0010.03916.83
7.0.40.0070.04116.96
7.0.30.0130.02216.91
7.0.20.0120.04716.84
7.0.10.0100.04016.87
7.0.00.0030.02716.96
5.6.400.0080.00814.90
5.6.390.0070.00714.82
5.6.380.0030.00614.70
5.6.370.0000.01614.66
5.6.360.0090.00014.23
5.6.350.0000.01214.60
5.6.340.0070.00314.13
5.6.330.0070.00314.49
5.6.320.0090.00614.75
5.6.310.0030.01414.30
5.6.300.0060.00614.90
5.6.290.0060.00614.54
5.6.280.0050.05017.91
5.6.270.0030.01314.82
5.6.260.0070.00714.41
5.6.250.0040.00714.77
5.6.240.0130.00014.29
5.6.230.0060.00614.40
5.6.220.0030.00614.46
5.6.210.0080.03317.52
5.6.200.0130.04016.30
5.6.190.0050.03717.60
5.6.180.0300.03517.55
5.6.170.0120.02917.37
5.6.160.0030.02817.55
5.6.150.0020.04016.29
5.6.140.0070.02716.38
5.6.130.0030.05016.30
5.6.120.0100.04017.76
5.6.110.0060.02617.70
5.6.100.0080.04417.81
5.6.90.0070.04517.67
5.6.80.0050.04517.46
5.6.70.0090.00314.48
5.6.60.0040.00814.65
5.6.50.0040.00714.38
5.6.40.0000.01514.63
5.6.30.0040.00714.31
5.6.20.0100.00714.30
5.6.10.0060.00614.38
5.6.00.0060.00314.61
5.5.380.0000.01314.39
5.5.370.0000.01114.50
5.5.360.0030.00914.15
5.5.350.0100.02317.30
5.5.340.0070.04316.20
5.5.330.0110.04117.31
5.5.320.0260.03617.44
5.5.310.0110.02817.30
5.5.300.0070.04316.14
5.5.290.0050.02916.20
5.5.280.0130.03817.47
5.5.270.0080.04517.69
5.5.260.0090.04317.79
5.5.250.0080.04417.54
5.5.240.0120.04417.38
5.5.230.0090.00614.57
5.5.220.0030.01014.62
5.5.210.0030.00814.51
5.5.200.0020.01214.44
5.5.190.0030.01014.50
5.5.180.0070.00714.51
5.5.170.0030.00914.03
5.5.160.0100.00713.99
5.5.150.0000.01414.37
5.5.140.0030.01014.59
5.5.130.0100.00314.55
5.5.120.0030.01014.26
5.5.110.0000.01414.52
5.5.100.0030.01014.05
5.5.90.0000.01614.02
5.5.80.0050.00914.20
5.5.70.0070.00714.46
5.5.60.0060.00814.17
5.5.50.0000.01114.21
5.5.40.0090.00614.35
5.5.30.0030.01014.40
5.5.20.0120.00614.75
5.5.10.0000.01714.10
5.5.00.0060.00914.16
5.4.450.0150.04015.22
5.4.440.0190.03715.20
5.4.430.0130.02615.21
5.4.420.0130.04215.26
5.4.410.0190.03315.24
5.4.400.0100.03815.21
5.4.390.0200.03715.17
5.4.380.0100.04215.19
5.4.370.0100.02415.21
5.4.360.0100.02215.09
5.4.350.0070.02515.20
5.4.340.0100.02515.21
5.4.330.0000.00711.05
5.4.320.0100.02715.13
5.4.310.0120.01715.23
5.4.300.0110.01915.08
5.4.290.0130.01815.13
5.4.280.0050.03015.38
5.4.270.0100.02215.23
5.4.260.0050.02715.10
5.4.250.0080.02015.16
5.4.240.0130.01815.18
5.4.230.0070.02415.05
5.4.220.0130.01714.95
5.4.210.0100.02015.01
5.4.200.0120.02015.18
5.4.190.0100.01815.03
5.4.180.0050.02615.07
5.4.170.0100.02215.18
5.4.160.0150.01815.16
5.4.150.0100.02215.13
5.4.140.0080.02214.05
5.4.130.0100.02613.81
5.4.120.0080.03213.84
5.4.110.0180.02813.70
5.4.100.0120.03213.98
5.4.90.0100.02513.92
5.4.80.0120.04013.96
5.4.70.0130.03013.69
5.4.60.0160.03313.97
5.4.50.0070.03914.00
5.4.40.0120.02913.82
5.4.30.0170.02313.64
5.4.20.0100.04013.79
5.4.10.0130.03213.91
5.4.00.0100.02213.49
5.3.290.0130.05314.54
5.3.280.0070.04314.57
5.3.270.0170.03314.65
5.3.260.0130.04014.45
5.3.250.0100.04014.45
5.3.240.0170.03314.53
5.3.230.0200.07314.46
5.3.220.0170.03314.43
5.3.210.0200.07314.40
5.3.200.0230.05714.42
5.3.190.0200.05714.41
5.3.180.0200.05314.65
5.3.170.0230.04314.55
5.3.160.0200.05014.59
5.3.150.0270.07014.51
5.3.140.0200.06714.39
5.3.130.0230.04014.41
5.3.120.0270.07014.40
5.3.110.0230.05014.49
5.3.100.0330.05713.94
5.3.90.0200.04313.88
5.3.80.0200.06314.00
5.3.70.0200.03713.86
5.3.60.0130.07313.94
5.3.50.0300.06013.85
5.3.40.0230.04313.79
5.3.30.0300.05713.86
5.3.20.0200.04713.48
5.3.10.0200.04713.68
5.3.00.0270.06713.66
5.2.170.0200.03713.33
5.2.160.0200.05713.33
5.2.150.0200.05713.33
5.2.140.0270.02013.33
5.2.130.0200.05713.33
5.2.120.0170.03713.33
5.2.110.0170.04013.33
5.2.100.0270.03313.33
5.2.90.0170.06313.33
5.2.80.0230.05013.33
5.2.70.0230.03313.33
5.2.60.0200.06013.33
5.2.50.0200.05013.33
5.2.40.0200.04713.33
5.2.30.0200.06013.33
5.2.20.0130.04713.33
5.2.10.0230.06013.33
5.2.00.0130.05713.33
5.1.60.0130.03313.33
5.1.50.0200.04313.33
5.1.40.0130.03313.33
5.1.30.0170.05013.33
5.1.20.0200.04013.33
5.1.10.0230.05013.33
5.1.00.0070.04313.33
5.0.50.0130.03713.33
5.0.40.0070.03713.33
5.0.30.0030.06013.33
5.0.20.0130.02713.33
5.0.10.0070.03713.33
5.0.00.0070.06313.33
4.4.90.0070.03713.33
4.4.80.0070.03713.33
4.4.70.0100.03013.33
4.4.60.0030.03013.33
4.4.50.0070.03313.33
4.4.40.0070.04013.33
4.4.30.0100.02013.33
4.4.20.0030.02313.33
4.4.10.0130.03013.33
4.4.00.0030.04313.33
4.3.110.0100.03313.33
4.3.100.0100.02713.33
4.3.90.0100.03013.33
4.3.80.0100.04013.33
4.3.70.0130.02713.33
4.3.60.0100.02713.33
4.3.50.0100.03013.33
4.3.40.0070.04313.33
4.3.30.0070.03013.33
4.3.20.0070.03013.33
4.3.10.0000.03313.33
4.3.00.0030.03013.33

preferences:
48.64 ms | 400 KiB | 5 Q