3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait ImmutableFromParams { private $mutable = true; private function __construct(array $params) {var_dump(get_object_vars($this));die;//array_intersect($params, (get_object_vars($this)))); die; foreach (array_intersect($params, (get_object_vars($this))) 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 $foo; 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() { return (string) $this->bar; } } $foo = MyValueObject::fromParams(array('foo' => 'foo', 'bar' => 'bar', 'meh' => 'meh')); $foo->setFoo('newfoo'); $foo->setDog('dog'); echo $foo; /* To Do: 1. Throw exception on attempted $foo->setFoo() of DTO. 2. Return new instance on attempted $foo->setFoo() of VO. 3. Implement an equality method for VO. 4. Add guard clause preventing string to array conversion in VO when nested array in $params. 5. Add guard for incomplete $params & throw exception (would require explicit NULLs in $params for permissable NULL values). Notes: - When we want to raise the bar and require all DTOs & VOs to enforce their own validation internally (using private setters), remove __call & references to $mutable from the Trait and limit add check for in_array($param, array_keys(get_object_vars($this)));. */

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.0070.00718.68
8.3.30.0090.00919.13
8.3.20.0070.00720.32
8.3.10.0040.00423.66
8.3.00.0090.00019.26
8.2.170.0110.00422.96
8.2.160.0090.00920.58
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0000.00726.16
8.2.120.0110.00020.49
8.2.110.0070.00320.80
8.2.100.0030.00717.91
8.2.90.0060.00317.91
8.2.80.0040.00417.97
8.2.70.0030.00617.50
8.2.60.0050.00517.92
8.2.50.0050.00318.07
8.2.40.0040.00420.07
8.2.30.0070.00018.18
8.2.20.0040.00417.80
8.2.10.0050.00218.12
8.2.00.0030.00617.70
8.1.270.0030.00622.01
8.1.260.0040.00426.35
8.1.250.0020.00528.09
8.1.240.0070.00322.20
8.1.230.0000.01120.94
8.1.220.0080.00017.88
8.1.210.0040.00718.92
8.1.200.0030.00617.47
8.1.190.0050.00517.48
8.1.180.0050.00318.10
8.1.170.0060.00318.69
8.1.160.0000.00722.09
8.1.150.0000.00818.90
8.1.140.0020.00517.33
8.1.130.0000.00717.71
8.1.120.0050.00217.54
8.1.110.0050.00317.43
8.1.100.0030.00417.44
8.1.90.0040.00417.39
8.1.80.0040.00417.46
8.1.70.0000.00717.43
8.1.60.0000.00917.48
8.1.50.0040.00417.58
8.1.40.0040.00417.44
8.1.30.0060.00317.55
8.1.20.0040.00417.68
8.1.10.0030.00617.46
8.1.00.0040.00417.50
8.0.300.0030.00520.05
8.0.290.0040.00417.00
8.0.280.0000.00818.42
8.0.270.0000.00717.32
8.0.260.0070.00017.23
8.0.250.0030.00317.15
8.0.240.0050.00316.99
8.0.230.0070.00016.95
8.0.220.0070.00017.03
8.0.210.0030.00517.00
8.0.200.0000.00717.04
8.0.190.0040.00417.13
8.0.180.0080.00016.97
8.0.170.0040.00416.98
8.0.160.0070.00317.04
8.0.150.0000.00717.00
8.0.140.0030.00616.80
8.0.130.0000.00613.35
8.0.120.0040.00416.85
8.0.110.0070.00317.04
8.0.100.0000.00716.90
8.0.90.0070.00016.76
8.0.80.0030.01316.91
8.0.70.0000.00816.85
8.0.60.0040.00416.91
8.0.50.0030.00516.76
8.0.30.0130.01117.24
8.0.20.0100.00817.40
8.0.10.0000.00817.07
8.0.00.0100.00816.86
7.4.330.0000.00515.02
7.4.320.0030.00316.43
7.4.300.0040.00416.66
7.4.290.0030.00516.52
7.4.280.0040.00416.60
7.4.270.0040.00416.44
7.4.260.0030.00316.45
7.4.250.0000.00816.52
7.4.240.0050.00216.62
7.4.230.0040.00416.72
7.4.220.0040.01616.38
7.4.210.0030.01216.39
7.4.200.0000.00716.70
7.4.160.0120.00416.51
7.4.150.0140.00617.40
7.4.140.0120.00917.86
7.4.130.0080.01116.52
7.4.120.0050.01316.58
7.4.110.0140.01116.69
7.4.100.0140.00416.57
7.4.90.0070.01016.67
7.4.80.0120.00619.39
7.4.70.0130.00316.45
7.4.60.0030.01316.51
7.4.50.0000.00816.60
7.4.40.0090.00616.73
7.4.30.0120.00916.75
7.4.00.0110.00614.83
7.3.330.0000.00513.26
7.3.320.0020.00213.36
7.3.310.0030.00316.40
7.3.300.0070.00016.39
7.3.290.0090.01216.41
7.3.280.0090.00616.38
7.3.270.0120.00617.40
7.3.260.0060.01216.35
7.3.250.0090.00916.46
7.3.240.0070.01016.63
7.3.230.0100.00716.50
7.3.210.0000.01816.43
7.3.200.0100.01019.39
7.3.190.0060.01016.32
7.3.180.0060.00916.36
7.3.170.0060.01116.41
7.3.160.0100.00616.52
7.3.120.0100.00714.72
7.3.110.0060.01214.62
7.3.100.0060.00314.82
7.3.90.0000.01414.94
7.3.80.0060.00614.82
7.3.70.0000.01114.78
7.3.60.0110.00414.86
7.3.50.0040.00414.89
7.3.40.0120.00314.96
7.3.30.0060.00614.80
7.3.20.0070.00716.50
7.3.10.0130.00116.69
7.3.00.0040.00716.70
7.2.330.0180.00416.74
7.2.320.0130.00316.45
7.2.310.0120.00616.73
7.2.300.0040.01316.77
7.2.290.0070.01716.59
7.2.250.0130.00715.20
7.2.240.0060.01214.86
7.2.230.0030.01515.13
7.2.220.0090.00614.93
7.2.210.0100.00614.93
7.2.200.0060.00615.10
7.2.190.0070.00714.75
7.2.180.0060.00614.89
7.2.170.0030.01215.10
7.2.130.0080.00616.87
7.2.120.0050.00716.90
7.2.110.0060.00816.61
7.2.100.0050.00416.77
7.2.90.0050.00616.86
7.2.80.0100.00616.72
7.2.70.0070.00616.77
7.2.60.0070.00516.75
7.2.50.0050.00916.93
7.2.40.0080.00516.69
7.2.30.0080.00316.78
7.2.20.0080.00616.67
7.2.10.0010.01116.85
7.2.00.0070.00516.83
7.1.330.0130.00315.89
7.1.320.0090.00615.77
7.1.310.0040.00815.74
7.1.300.0090.00015.59
7.1.290.0030.01015.45
7.1.280.0080.00515.45
7.1.270.0000.01015.82
7.1.260.0030.00615.51
7.1.250.0030.00615.87
7.1.200.0030.00915.49
7.1.70.0030.00317.20
7.1.60.0100.01419.11
7.1.50.0140.01016.78
7.1.00.0030.07722.51
7.0.200.0000.00716.63
7.0.140.0070.07322.01
7.0.60.0030.04320.07
7.0.50.0100.07717.87
7.0.40.0170.07320.06
7.0.30.0170.06720.06
7.0.20.0270.06020.24
7.0.10.0030.04320.07
7.0.00.0100.08320.16
5.6.280.0030.07020.95
5.6.210.0070.08320.50
5.6.200.0000.07318.22
5.6.190.0100.03720.66
5.6.180.0200.07020.77
5.6.170.0370.03720.54
5.6.160.0030.05320.54
5.6.150.0200.06718.36
5.6.140.0070.07018.20
5.6.130.0070.03718.17
5.6.120.0030.04020.95
5.6.110.0000.09021.03
5.6.100.0200.07321.09
5.6.90.0030.09021.13
5.6.80.0030.04020.40
5.5.350.0130.08320.47
5.5.340.0070.08017.96
5.5.330.0030.05320.31
5.5.320.0370.06020.31
5.5.310.0200.08320.34
5.5.300.0170.06017.99
5.5.290.0070.04718.00
5.5.280.0070.04720.82
5.5.270.0130.08020.81
5.5.260.0170.07020.98
5.5.250.0030.04020.45
5.5.240.0200.07320.29
5.4.450.1030.04019.17
5.4.440.0570.05319.38
5.4.430.1030.05019.58
5.4.420.0670.00019.36
5.4.410.0670.00019.30
5.4.400.0630.00019.22
5.4.390.0630.00019.24
5.4.380.0630.00019.07
5.4.370.0630.00019.07
5.4.360.0600.00019.09
5.4.350.0630.00019.21
5.4.340.0090.04012.04
5.4.320.0080.03512.53
5.4.310.0040.04412.53
5.4.300.0030.04612.53
5.4.290.0050.04312.52
5.4.280.0040.03912.41
5.4.270.0060.03912.41
5.4.260.0080.03712.42
5.4.250.0080.03612.41
5.4.240.0070.03612.42
5.4.230.0070.03912.41
5.4.220.0080.04212.41
5.4.210.0110.03312.41
5.4.200.0070.03712.41
5.4.190.0110.03212.41
5.4.180.0040.04212.40
5.4.170.0090.03512.41
5.4.160.0070.03512.41
5.4.150.0060.03712.41
5.4.140.0120.04312.09
5.4.130.0090.04412.08
5.4.120.0060.03712.04
5.4.110.0060.03612.04
5.4.100.0040.04512.04
5.4.90.0060.03712.04
5.4.80.0090.03412.04
5.4.70.0070.03412.03
5.4.60.0060.04212.04
5.4.50.0080.04412.03
5.4.40.0060.04212.02
5.4.30.0080.03712.02
5.4.20.0030.04012.02
5.4.10.0060.03612.02
5.4.00.0080.04011.51
5.3.290.0100.04712.80
5.3.280.0110.04012.71
5.3.270.0040.04712.72
5.3.260.0090.04612.72
5.3.250.0060.03812.72
5.3.240.0060.03812.72
5.3.230.0100.03712.71
5.3.220.0090.03312.68
5.3.210.0080.04112.68
5.3.200.0080.03612.68
5.3.190.0080.03812.68
5.3.180.0070.03712.67
5.3.170.0100.03412.67
5.3.160.0070.03712.67
5.3.150.0080.03612.67
5.3.140.0060.04112.66
5.3.130.0080.03912.65
5.3.120.0080.04412.65
5.3.110.0090.04412.66
5.3.100.0100.04512.11
5.3.90.0080.04212.08
5.3.80.0070.03712.08
5.3.70.0050.03812.07
5.3.60.0080.03512.06
5.3.50.0070.03612.00
5.3.40.0060.03712.00
5.3.30.0080.04211.95
5.3.20.0090.03911.72
5.3.10.0100.03911.70
5.3.00.0040.03911.68
5.2.170.0060.0299.18
5.2.160.0070.0359.18
5.2.150.0040.0319.18
5.2.140.0070.0289.18
5.2.130.0050.0339.14
5.2.120.0060.0389.14
5.2.110.0070.0279.15
5.2.100.0050.0299.15
5.2.90.0060.0299.14
5.2.80.0030.0329.14
5.2.70.0040.0309.14
5.2.60.0040.0359.10
5.2.50.0050.0309.06
5.2.40.0050.0289.04
5.2.30.0060.0319.02
5.2.20.0040.0339.01
5.2.10.0030.0328.93
5.2.00.0060.0278.79
5.1.60.0010.0288.07
5.1.50.0050.0278.07
5.1.40.0080.0328.05
5.1.30.0010.0318.39
5.1.20.0050.0268.42
5.1.10.0040.0278.14
5.1.00.0050.0288.14
5.0.50.0020.0256.63
5.0.40.0060.0246.48
5.0.30.0030.0356.29
5.0.20.0030.0196.27
5.0.10.0070.0236.25
5.0.00.0030.0406.23
4.4.90.0040.0154.78
4.4.80.0030.0154.75
4.4.70.0020.0164.75
4.4.60.0000.0214.75
4.4.50.0020.0164.77
4.4.40.0010.0274.71
4.4.30.0020.0184.76
4.4.20.0020.0214.84
4.4.10.0050.0164.85
4.4.00.0050.0274.76
4.3.110.0030.0164.67
4.3.100.0050.0134.66
4.3.90.0050.0164.63
4.3.80.0020.0274.58
4.3.70.0040.0154.63
4.3.60.0080.0114.62
4.3.50.0030.0184.63
4.3.40.0050.0394.53
4.3.30.0010.0193.29
4.3.20.0030.0163.26
4.3.10.0040.0203.22
4.3.00.0100.0177.23

preferences:
48.54 ms | 400 KiB | 5 Q