3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait ImmutableFromParams { private $mutable = true; private function __construct(array $params) { foreach ($params as $key => $value) { $this->{'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)))}($value); } unset($this->mutable); } public static function fromParams(array $params) { return new static($params); } public function __call($method, $args) { if (isset($this->mutable) && substr($method, 0, 3) == 'set' && property_exists($this, lcfirst(substr($method, 3)))) { $this->{lcfirst(substr($method, 3))} = reset($args); } } } interface DataTransferObjectInterface { public static function fromParams(array $params); public function asArray(); } abstract class AbstractDataTransferObject implements DataTransferObjectInterface { use ImmutableFromParams; public function asArray() { return get_object_vars($this); } } final class MyDataTransferObject extends AbstractDataTransferObject { protected $fooBoo; protected $bar; protected function setBar($value) { $this->bar = $value; } } $foo = MyDataTransferObject::fromParams(array('foo' => 'foo', 'bar' => 'bar', 'meh' => 'meh')); $foo->setFoo('newfoo'); $foo->setDog('dog'); var_dump($foo->asArray()); interface ValueObjectInterface { public static function fromParams(array $params); public function __toString(); } abstract class AbstractValueObject implements ValueObjectInterface { use ImmutableFromParams; abstract public function __toString(); } final class MyValueObject extends AbstractValueObject { protected $bar; protected function setBar($value) { $this->bar = $value; } public function __toString() { echo $bar; } } $foo = MyValueObject::fromParams(array('foo' => 'foo', 'bar' => 'bar', 'meh' => 'meh')); $foo->setFoo('newfoo'); $foo->setDog('dog'); echo $foo;

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.70.0100.01016.88
8.3.60.0090.00618.41
8.3.50.0090.00921.14
8.3.40.0070.01518.88
8.3.30.0090.00619.21
8.3.20.0060.00320.19
8.3.10.0040.00423.52
8.3.00.0030.00619.25
8.2.180.0030.01318.66
8.2.170.0060.00922.96
8.2.160.0090.00920.10
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0050.00326.16
8.2.120.0070.00320.32
8.2.110.0090.01320.51
8.2.100.0040.00718.16
8.2.90.0000.00819.27
8.2.80.0000.00817.97
8.2.70.0040.00417.75
8.2.60.0040.00417.80
8.2.50.0050.00518.07
8.2.40.0040.00419.82
8.2.30.0080.00018.13
8.2.20.0040.00417.75
8.2.10.0030.00618.05
8.2.00.0040.00417.73
8.1.280.0180.00325.92
8.1.270.0030.00623.91
8.1.260.0080.00026.35
8.1.250.0070.00028.09
8.1.240.0100.00723.77
8.1.230.0070.00418.97
8.1.220.0050.00317.89
8.1.210.0060.00318.77
8.1.200.0110.00017.48
8.1.190.0080.00017.47
8.1.180.0040.00418.10
8.1.170.0040.00418.63
8.1.160.0080.00022.04
8.1.150.0070.00018.94
8.1.140.0080.00017.52
8.1.130.0030.00317.89
8.1.120.0050.00217.58
8.1.110.0000.00717.52
8.1.100.0080.00017.41
8.1.90.0000.00717.45
8.1.80.0040.00417.57
8.1.70.0080.00017.47
8.1.60.0000.00917.71
8.1.50.0030.00617.49
8.1.40.0030.00617.53
8.1.30.0060.00317.56
8.1.20.0050.00317.71
8.1.10.0030.00517.59
8.1.00.0050.00317.52
8.0.300.0040.00418.77
8.0.290.0070.00016.88
8.0.280.0070.00018.50
8.0.270.0040.00417.32
8.0.260.0080.00017.32
8.0.250.0050.00317.00
8.0.240.0040.00417.01
8.0.230.0050.00217.04
8.0.220.0000.00616.95
8.0.210.0000.00716.93
8.0.200.0030.00317.04
8.0.190.0030.00317.10
8.0.180.0040.00416.92
8.0.170.0050.00316.94
8.0.160.0050.00417.04
8.0.150.0000.00716.98
8.0.140.0050.00216.98
8.0.130.0000.00513.43
8.0.120.0050.00217.00
8.0.110.0050.00517.04
8.0.100.0040.00416.90
8.0.90.0040.00416.96
8.0.80.0070.01017.06
8.0.70.0040.00416.93
8.0.60.0040.00416.96
8.0.50.0050.00316.95
8.0.30.0070.01417.01
8.0.20.0090.01417.40
8.0.10.0040.00417.19
8.0.00.0110.00616.94
7.4.330.0020.00215.08
7.4.320.0040.00416.62
7.4.300.0000.00616.67
7.4.290.0030.00516.62
7.4.280.0050.00316.61
7.4.270.0000.00716.59
7.4.260.0000.00716.64
7.4.250.0030.00516.67
7.4.240.0040.00416.56
7.4.230.0050.00316.64
7.4.220.0110.01416.52
7.4.210.0070.00716.60
7.4.200.0040.00416.56
7.4.160.0100.00716.70
7.4.150.0070.01017.40
7.4.140.0170.00417.86
7.4.130.0060.01316.69
7.4.120.0080.01216.47
7.4.110.0120.00616.66
7.4.100.0070.01016.71
7.4.90.0060.01016.42
7.4.80.0150.00619.39
7.4.70.0070.01416.59
7.4.60.0000.01716.65
7.4.50.0060.00016.43
7.4.40.0060.01116.44
7.4.30.0070.01016.64
7.4.00.0090.00515.01
7.3.330.0000.00513.40
7.3.320.0000.00513.43
7.3.310.0030.00516.44
7.3.300.0030.00316.45
7.3.290.0100.01016.41
7.3.280.0080.01016.42
7.3.270.0070.01017.40
7.3.260.0120.00616.56
7.3.250.0080.00816.32
7.3.240.0150.00916.72
7.3.230.0100.00716.66
7.3.210.0080.00816.36
7.3.200.0070.01119.39
7.3.190.0150.00916.34
7.3.180.0100.00716.67
7.3.170.0100.01016.39
7.3.160.0050.01116.50
7.3.120.0140.00415.04
7.3.110.0100.00714.82
7.3.100.0000.01514.74
7.3.90.0060.00315.02
7.3.80.0030.00714.84
7.3.70.0000.01314.69
7.3.60.0080.00814.93
7.3.50.0060.00914.78
7.3.40.0090.00614.91
7.3.30.0110.00314.84
7.3.20.0030.00916.64
7.3.10.0040.00716.57
7.3.00.0030.01316.70
7.2.330.0120.00616.54
7.2.320.0090.01216.83
7.2.310.0090.01216.71
7.2.300.0090.00916.65
7.2.290.0070.01116.55
7.2.250.0100.00715.03
7.2.240.0030.01615.43
7.2.230.0060.00914.92
7.2.220.0080.00415.29
7.2.210.0030.01015.10
7.2.200.0070.00714.89
7.2.190.0070.01015.26
7.2.180.0000.01415.09
7.2.170.0120.00315.00
7.2.130.0060.00916.57
7.2.120.0060.00916.73
7.2.110.0140.01116.70
7.2.100.0220.00616.86
7.2.90.0110.01516.97
7.2.80.0030.01316.75
7.2.70.0200.00616.83
7.2.60.0100.01016.95
7.2.50.0160.01017.05
7.2.40.0090.00916.64
7.2.30.0130.00816.69
7.2.20.0080.01316.70
7.2.10.0140.00516.59
7.2.00.0100.00716.85
7.1.330.0060.00615.61
7.1.320.0100.00315.47
7.1.310.0030.00915.95
7.1.300.0030.01015.81
7.1.290.0100.00315.84
7.1.280.0030.01015.76
7.1.270.0080.00415.83
7.1.260.0040.01115.83
7.1.250.0090.00915.80
7.1.240.0060.01015.58
7.1.230.0090.01015.77
7.1.220.0220.00315.49
7.1.210.0140.00615.89
7.1.200.0090.01115.44
7.1.190.0150.00715.52
7.1.180.0190.00815.46
7.1.170.0150.00315.51
7.1.160.0100.00915.70
7.1.150.0100.00715.61
7.1.140.0130.00915.77
7.1.130.0040.01115.63
7.1.120.0040.00715.50
7.1.110.0030.01215.81
7.1.100.0080.00716.98
7.1.90.0060.00615.32
7.1.80.0100.00415.45
7.1.70.0040.01016.28
7.1.60.0110.00917.38
7.1.50.0130.00916.26
7.1.40.0070.01015.60
7.1.30.0160.00015.38
7.1.20.0120.00415.50
7.1.10.0090.00915.54
7.1.00.0060.04319.05
7.0.330.0070.00715.23
7.0.320.0100.01015.37
7.0.310.0100.00715.22
7.0.300.0120.01515.02
7.0.290.0030.01015.05
7.0.280.0070.01115.42
7.0.270.0040.01215.35
7.0.260.0030.01315.00
7.0.250.0070.00715.29
7.0.240.0100.01015.43
7.0.230.0140.00815.11
7.0.220.0090.01215.30
7.0.210.0100.01314.97
7.0.200.0040.01015.95
7.0.190.0210.00315.13
7.0.180.0180.00815.45
7.0.170.0130.01315.49
7.0.160.0100.01115.60
7.0.150.0100.01015.44
7.0.140.0090.03618.74
7.0.130.0110.00414.95
7.0.120.0170.00315.13
7.0.110.0090.00915.37
7.0.100.0040.01515.17
7.0.90.0080.01215.45
7.0.80.0110.00414.96
7.0.70.0140.00315.38
7.0.60.0100.04717.66
7.0.50.0080.03516.63
7.0.40.0140.04016.72
7.0.30.0190.03116.74
7.0.20.0140.04916.82
7.0.10.0180.02316.84
7.0.00.0030.02316.73
5.6.380.0030.01714.43
5.6.370.0000.01514.73
5.6.360.0040.01214.47
5.6.350.0070.00514.41
5.6.340.0110.00313.84
5.6.330.0070.00714.57
5.6.320.0100.00314.69
5.6.310.0070.01014.67
5.6.300.0130.00714.54
5.6.290.0160.00714.40
5.6.280.0080.04317.79
5.6.270.0140.00714.55
5.6.260.0130.00814.48
5.6.250.0030.01314.53
5.6.240.0090.00914.54
5.6.230.0000.01414.10
5.6.220.0060.00914.16
5.6.210.0030.03117.66
5.6.200.0070.03816.13
5.6.190.0060.03817.32
5.6.180.0140.02717.49
5.6.170.0070.02917.20
5.6.160.0030.03017.44
5.6.150.0090.02716.21
5.6.140.0020.02516.31
5.6.130.0070.02216.19
5.6.120.0090.03917.45
5.6.110.0150.03517.60
5.6.100.0050.04617.59
5.6.90.0080.04517.59
5.6.80.0130.04017.22
5.6.70.2350.02017.34
5.6.60.0030.01014.33
5.6.50.0000.01314.68
5.6.40.0080.00614.40
5.6.30.0030.00914.20
5.6.20.0030.00914.19
5.6.10.0040.01114.41
5.6.00.0100.00614.31
5.5.380.0070.00511.05
5.5.370.0090.00010.93
5.5.360.0030.01010.90
5.5.350.0050.04715.76
5.5.340.0080.03914.45
5.5.330.0090.02115.71
5.5.320.0180.02515.84
5.5.310.0160.03615.69
5.5.300.0070.02914.56
5.5.290.0050.04514.53
5.5.280.0040.02415.98
5.5.270.0050.04715.78
5.5.260.0060.04315.88
5.5.250.0080.04515.80
5.5.240.0170.03215.58
5.5.230.0030.00511.30
5.5.220.0050.00310.96
5.5.210.0040.00411.08
5.5.200.0050.00310.93
5.5.190.0070.00311.09
5.5.180.0050.00510.94
5.5.170.0050.00510.90
5.5.160.0030.00710.90
5.5.150.0050.00511.15
5.5.140.0090.00611.29
5.5.130.0090.00311.07
5.5.120.0050.00311.20
5.5.110.0000.01210.90
5.5.100.0040.00711.17
5.5.90.0030.00610.90
5.5.80.0020.00711.27
5.5.70.0020.00510.90
5.5.60.0000.01111.12
5.5.50.0080.00410.90
5.5.40.0040.00811.13
5.5.30.0070.00411.15
5.5.20.0040.00811.31
5.5.10.0040.00411.07
5.5.00.0000.00911.03
5.4.450.0370.03815.23
5.4.440.0400.03115.28
5.4.430.0080.03315.22
5.4.420.0360.00215.26
5.4.410.0350.00315.23
5.4.400.0350.00314.91
5.4.390.0440.00115.05
5.4.380.0370.00315.28
5.4.370.0360.00315.15
5.4.360.0320.00715.02
5.4.350.0370.00115.06
5.4.340.0090.01811.47
5.4.330.0070.00710.90
5.4.320.0060.02111.71
5.4.310.0020.02511.71
5.4.300.0050.02511.79
5.4.290.0040.02311.79
5.4.280.0050.02311.66
5.4.270.0070.01911.66
5.4.260.0100.01811.66
5.4.250.0070.01911.66
5.4.240.0050.02011.66
5.4.230.0050.02511.68
5.4.220.0020.02311.66
5.4.210.0070.01911.72
5.4.200.0060.02011.69
5.4.190.0060.02411.73
5.4.180.0050.02211.85
5.4.170.0050.02011.66
5.4.160.0040.02111.66
5.4.150.0050.02411.79
5.4.140.0090.01811.50
5.4.130.0040.02211.52
5.4.120.0050.01911.51
5.4.110.0060.02111.47
5.4.100.0080.01811.53
5.4.90.0050.02111.47
5.4.80.0050.02211.47
5.4.70.0050.02011.50
5.4.60.0060.02411.54
5.4.50.0050.02011.49
5.4.40.0040.02111.63
5.4.30.0060.02111.61
5.4.20.0040.02411.55
5.4.10.0040.02111.48
5.4.00.0050.02011.27
5.3.290.0020.02311.85
5.3.280.0040.02111.80
5.3.270.0040.02411.81
5.3.260.0020.02611.81
5.3.250.0060.02011.81
5.3.240.0070.02011.81
5.3.230.0060.01911.80
5.3.220.0040.01911.79
5.3.210.0080.02011.79
5.3.200.0040.02311.79
5.3.190.0060.02011.79
5.3.180.0060.01711.79
5.3.170.0070.01711.78
5.3.160.0040.02111.79
5.3.150.0040.02111.79
5.3.140.0050.01911.78
5.3.130.0030.02111.78
5.3.120.0050.02211.78
5.3.110.0050.02111.78
5.3.100.0070.02211.51
5.3.90.0070.01811.49
5.3.80.0030.02411.49
5.3.70.0050.01911.49
5.3.60.0030.02111.48
5.3.50.0040.02111.45
5.3.40.0050.01911.45
5.3.30.0030.02011.42
5.3.20.0060.01811.31
5.3.10.0050.01911.30
5.3.00.0050.02211.29
5.2.170.0030.01910.04
5.2.160.0060.01410.04
5.2.150.0060.01810.04
5.2.140.0030.01810.04
5.2.130.0060.01810.02
5.2.120.0060.01610.02
5.2.110.0040.01510.02
5.2.100.0020.01610.02
5.2.90.0050.01410.02
5.2.80.0020.01910.02
5.2.70.0060.01410.02
5.2.60.0040.01810.00
5.2.50.0020.0209.98
5.2.40.0060.0159.97
5.2.30.0020.0239.96
5.2.20.0020.0189.95
5.2.10.0040.0179.91
5.2.00.0020.0179.84
5.1.60.0020.0159.48
5.1.50.0030.0159.48
5.1.40.0060.0139.47
5.1.30.0050.0139.65
5.1.20.0060.0179.66
5.1.10.0030.0179.52
5.1.00.0060.0139.52
5.0.50.0050.0108.76
5.0.40.0040.0138.69
5.0.30.0030.0178.60
5.0.20.0050.0098.58
5.0.10.0030.0118.57
5.0.00.0050.0158.57
4.4.90.0020.0107.84
4.4.80.0050.0087.83
4.4.70.0050.0077.83
4.4.60.0030.0087.83
4.4.50.0040.0097.84
4.4.40.0010.0167.80
4.4.30.0020.0117.83
4.4.20.0050.0077.87
4.4.10.0040.0097.87
4.4.00.0030.0197.83
4.3.110.0020.0117.79
4.3.100.0010.0117.78
4.3.90.0010.0107.77
4.3.80.0050.0127.74
4.3.70.0010.0127.77
4.3.60.0010.0117.76
4.3.50.0020.0107.76
4.3.40.0020.0177.72
4.3.30.0040.0107.09
4.3.20.0020.0097.08
4.3.10.0020.0097.06
4.3.00.0080.0159.06

preferences:
45.41 ms | 401 KiB | 5 Q