3v4l.org

run code in 300+ PHP versions simultaneously
<?php declare(strict_types=1); namespace Dshafik; class Struct { // Because gettype() and ReflectionType->__toString() are inconsistent /** * @var array Type mappings */ private $__typeMap = [ 'int' => 'integer', 'bool' => 'boolean', 'float' => 'double', ]; /** * @var array Reflection data */ private $__reflection = []; /** * @var array The struct values */ protected $__values = []; public function __construct() { $this->introspect(); $this->hoist(func_get_args()); } public function __get($what) { return $this->__values[$what]; } public function __set($what, $value) { if (($type = gettype($value)) === $this->__reflection[$what]) { return $this->__values[$what] = $value; } else { throw new \TypeError("Key '$what' must be of type {$this->__reflection[$what]}, $type given."); } } final protected function introspect() { if ($this->__reflection) { return; } $class = new \ReflectionObject($this); $constructor = $class->getConstructor(); foreach ($constructor->getParameters() as $arg) { $type = (string) $arg->getType(); $this->__reflection[$arg->name] = $this->__typeMap[$type] ?? $type; } } final protected function hoist($args) { $this->introspect(); $i = 0; foreach ($this->__reflection as $key => $type) { $this->__set($key, $args[$i]); $i++; } } } // With strict types, will throw a TypeError, or coerce otherwise on mismatch $struct = new class(1, "Hello") extends Struct { public function __construct(int $foo, string $bar) { $this->hoist(func_get_args()); } }; var_dump($struct); // Works $struct->foo = 2; var_dump($struct); // Will throw a TypeError $struct->foo = 'World';

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.0070.01116.75
8.3.60.0110.01118.68
8.3.50.0080.01122.06
8.3.40.0070.01018.96
8.3.30.0040.01819.10
8.3.20.0030.00518.85
8.3.10.0050.00323.61
8.3.00.0030.00620.84
8.2.190.0140.00716.88
8.2.180.0090.00618.54
8.2.170.0140.00718.99
8.2.160.0070.00722.96
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0090.00026.16
8.2.120.0030.00621.06
8.2.110.0030.00620.95
8.2.100.0090.00319.48
8.2.90.0050.00319.33
8.2.80.0040.00417.97
8.2.70.0040.00417.75
8.2.60.0030.00618.16
8.2.50.0000.00818.07
8.2.40.0000.00818.34
8.2.30.0000.00718.27
8.2.20.0090.00017.84
8.2.10.0030.00518.04
8.2.00.0070.00018.03
8.1.280.0060.00825.92
8.1.270.0040.01520.38
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0040.00820.84
8.1.230.0110.00017.75
8.1.220.0000.00917.74
8.1.210.0000.01118.77
8.1.200.0070.00317.23
8.1.190.0040.00417.35
8.1.180.0080.00018.10
8.1.170.0000.00820.41
8.1.160.0040.00421.99
8.1.150.0040.00419.02
8.1.140.0060.00317.39
8.1.130.0000.00717.95
8.1.120.0040.00417.55
8.1.110.0020.00517.49
8.1.100.0040.00817.49
8.1.90.0030.00517.39
8.1.80.0000.00717.41
8.1.70.0040.00417.50
8.1.60.0000.00817.57
8.1.50.0050.00517.45
8.1.40.0040.00417.46
8.1.30.0050.00317.57
8.1.20.0030.00617.67
8.1.10.0050.00317.58
8.1.00.0040.00417.54
8.0.300.0040.00418.77
8.0.290.0070.00016.75
8.0.280.0040.00418.50
8.0.270.0070.00017.33
8.0.260.0030.00317.25
8.0.250.0000.00717.04
8.0.240.0070.00017.01
8.0.230.0070.00017.00
8.0.220.0000.00717.02
8.0.210.0030.00316.95
8.0.200.0030.00616.97
8.0.190.0040.00416.95
8.0.180.0000.00716.94
8.0.170.0000.00716.89
8.0.160.0000.00816.95
8.0.150.0070.00016.97
8.0.140.0110.00016.97
8.0.130.0030.00313.41
8.0.120.0080.00016.86
8.0.110.0070.00016.92
8.0.100.0040.00416.88
8.0.90.0040.00416.79
8.0.80.0180.00317.04
8.0.70.0020.00517.10
8.0.60.0040.00416.84
8.0.50.0000.00816.86
8.0.30.0080.01017.25
8.0.20.0070.01317.40
8.0.10.0050.00317.05
8.0.00.0110.01016.79
7.4.330.0000.00715.03
7.4.320.0060.00016.64
7.4.300.0030.00316.52
7.4.290.0050.00216.63
7.4.280.0030.00516.47
7.4.270.0000.00816.64
7.4.260.0070.00016.68
7.4.250.0040.00416.59
7.4.240.0020.00516.54
7.4.230.0000.00716.75
7.4.220.0070.01016.68
7.4.210.0130.00316.70
7.4.200.0070.00016.61
7.4.160.0070.01116.44
7.4.150.0080.01917.40
7.4.140.0130.01117.86
7.4.130.0110.01016.60
7.4.120.0120.00616.49
7.4.110.0200.00516.49
7.4.100.0090.01516.47
7.4.90.0030.01516.54
7.4.80.0120.00819.39
7.4.70.0140.00316.54
7.4.60.0090.00916.45
7.4.50.0040.00416.73
7.4.40.0030.01316.51
7.4.30.0060.01316.61
7.4.10.0060.01314.78
7.4.00.0100.00814.88
7.3.330.0030.00313.43
7.3.320.0050.00013.30
7.3.310.0030.00316.51
7.3.300.0030.00316.46
7.3.290.0060.01116.50
7.3.280.0070.01116.46
7.3.270.0050.01417.40
7.3.260.0030.01316.51
7.3.250.0090.01316.53
7.3.240.0110.00816.49
7.3.230.0030.01716.49
7.3.210.0160.00316.47
7.3.200.0070.01019.39
7.3.190.0140.00416.52
7.3.180.0140.00316.64
7.3.170.0090.01216.54
7.3.160.0090.01016.57
7.3.130.0060.01315.02
7.3.120.0060.00914.90
7.3.110.0060.01015.00
7.3.100.0120.00315.10
7.3.90.0090.00614.95
7.3.80.0080.00314.72
7.3.70.0040.01114.72
7.3.60.0090.00314.70
7.3.50.0090.00314.98
7.3.40.0130.00014.89
7.3.30.0000.01414.64
7.3.20.0040.01416.77
7.3.10.0050.00816.71
7.3.00.0060.00616.65
7.2.330.0120.00816.69
7.2.320.0080.01116.76
7.2.310.0110.00716.78
7.2.300.0110.01216.73
7.2.290.0080.01116.85
7.2.260.0040.01515.25
7.2.250.0060.01114.74
7.2.240.0000.01414.84
7.2.230.0060.00915.00
7.2.220.0120.00415.39
7.2.210.0000.01214.99
7.2.200.0090.00615.15
7.2.190.0040.01115.24
7.2.180.0090.00615.20
7.2.170.0090.00615.20
7.2.160.0100.00715.23
7.2.150.0120.00016.90
7.2.140.0130.00316.89
7.2.130.0030.01116.72
7.2.120.0090.00516.93
7.2.110.0080.00816.82
7.2.100.0030.00816.77
7.2.90.0040.00816.87
7.2.80.0050.01117.02
7.2.70.0030.00916.91
7.2.60.0070.00417.02
7.2.50.0030.00916.95
7.2.40.0090.00616.97
7.2.30.0060.00616.95
7.2.20.0070.00517.01
7.2.10.0060.00717.12
7.2.00.0060.00617.04
7.1.330.0120.00015.71
7.1.320.0030.00915.86
7.1.310.0030.01015.78
7.1.300.0040.00715.73
7.1.290.0040.00415.81
7.1.280.0060.00615.55
7.1.270.0000.01815.88
7.1.260.0000.01215.97
7.1.250.0090.00215.77
7.1.240.0060.00615.73
7.1.230.0030.01115.86
7.1.220.0050.00315.74
7.1.210.0070.00715.69
7.1.200.0060.00615.87
7.1.190.0070.00715.92
7.1.180.0060.00615.70
7.1.170.0080.00815.80
7.1.160.0020.00915.80
7.1.150.0050.00815.89
7.1.140.0030.01015.62
7.1.130.0030.00815.86
7.1.120.0060.00515.71
7.1.110.0070.00315.99
7.1.100.0080.00415.96
7.1.90.0050.00815.76
7.1.80.0050.00715.95
7.1.70.0090.00516.32
7.1.60.0020.01016.44
7.1.50.0060.00716.06
7.1.40.0070.00916.00
7.1.30.0020.00715.79
7.1.20.0020.01315.79
7.1.10.0080.00515.74
7.1.00.0040.03018.02
7.0.330.0050.00915.31
7.0.320.0030.00715.23
7.0.310.0050.00615.30
7.0.300.0090.00315.54
7.0.290.0030.01115.41
7.0.280.0080.00515.48
7.0.270.0090.00315.14
7.0.260.0050.00915.35
7.0.250.0030.00715.48
7.0.240.0040.00715.44
7.0.230.0100.00215.36
7.0.220.0020.00815.41
7.0.210.0040.00815.45
7.0.200.0070.00515.82
7.0.190.0030.01015.33
7.0.180.0070.00515.19
7.0.170.0040.00715.43
7.0.160.0060.00615.21
7.0.150.0080.00315.29
7.0.140.0040.00715.32
7.0.130.0060.00615.37
7.0.120.0040.01015.47
7.0.110.0040.00915.53
7.0.100.0060.00515.43
7.0.90.0030.00915.49
7.0.80.0070.00515.60
7.0.70.0030.00715.45
7.0.60.0070.02716.93
7.0.50.0030.01916.17
7.0.40.0060.03315.79
7.0.30.0120.01615.74
7.0.20.0190.02415.68
7.0.10.0040.03515.70
7.0.00.0090.01715.70
5.6.400.0030.00914.39
5.6.390.0000.01314.12
5.6.380.0070.00814.27
5.6.370.0060.00714.34
5.6.360.0100.00614.09
5.6.350.0070.00513.88
5.6.340.0050.00514.21
5.6.330.0050.00314.21
5.6.320.0060.00614.21
5.6.310.0050.00814.20
5.6.300.0070.00514.11
5.6.290.0070.00314.23
5.6.280.0000.03316.29
5.6.270.0100.00514.18
5.6.260.0040.00614.06
5.6.250.0060.00914.12
5.6.240.0020.00814.06
5.6.230.0080.00414.19
5.6.220.0040.01114.08
5.6.210.0070.03116.31
5.6.200.0060.03215.50
5.6.190.0050.03716.21
5.6.180.0190.02316.30
5.6.170.0110.03116.33
5.6.160.0030.02316.47
5.6.150.0060.03115.54
5.6.140.0050.01815.50
5.6.130.0030.03415.49
5.6.120.0050.02616.66
5.6.110.0050.02416.46
5.6.100.0050.03416.38
5.6.90.0050.03316.62
5.6.80.0040.03216.17
5.6.70.0030.00913.98
5.6.60.0040.00713.91
5.6.50.0000.01214.00
5.6.40.0040.00913.95
5.6.30.0020.00713.99
5.6.20.0060.00513.97
5.6.10.0030.00614.16
5.6.00.0020.01014.00
5.5.380.0070.00412.47
5.5.370.0050.00912.59
5.5.360.0070.00912.59
5.5.350.0060.02915.14
5.5.340.0070.02414.29
5.5.330.0080.02915.08
5.5.320.0180.02715.17
5.5.310.0150.01715.02
5.5.300.0050.03114.31
5.5.290.0050.03014.22
5.5.280.0070.02815.27
5.5.270.0050.02915.25
5.5.260.0070.03015.27
5.5.250.0100.02115.09
5.5.240.0000.01914.95
5.5.230.0030.01012.48
5.5.220.0060.00512.44
5.5.210.0020.00912.39
5.5.200.0090.00612.40
5.5.190.0040.00912.39
5.5.180.0050.00712.34
5.5.170.0020.01012.45
5.5.160.0070.00612.27
5.5.150.0080.00512.54
5.5.140.0030.00312.45
5.5.130.0050.00712.21
5.5.120.0020.00912.48
5.5.110.0070.00512.54
5.5.100.0030.00712.18
5.5.90.0040.00512.52
5.5.80.0040.00712.20
5.5.70.0070.00412.42
5.5.60.0030.00612.33
5.5.50.0060.00612.37
5.5.40.0030.00912.59
5.5.30.0040.00312.26
5.5.20.0080.00412.45
5.5.10.0060.00712.32
5.5.00.0020.01012.46
5.4.450.0210.01113.99
5.4.440.0270.02113.91
5.4.430.0310.02013.98
5.4.420.0090.01913.93
5.4.410.0020.03313.92
5.4.400.0070.02013.96
5.4.390.0030.02413.84
5.4.380.0030.02413.87
5.4.370.0060.02113.88
5.4.360.0080.01713.82
5.4.350.0060.02013.78
5.4.340.0090.01813.91
5.4.330.0030.00611.35
5.4.320.0040.02213.91
5.4.310.0040.02313.80
5.4.300.0060.02213.89
5.4.290.0060.02213.87
5.4.280.0060.02813.86
5.4.270.0070.02113.90
5.4.260.0080.02313.91
5.4.250.0050.03013.89
5.4.240.0020.03213.77
5.4.230.0090.02513.85
5.4.220.0070.02813.83
5.4.210.0080.02113.92
5.4.200.0050.02213.08
5.4.190.0080.01713.87
5.4.180.0050.02413.85
5.4.170.0060.02613.84
5.4.160.0130.01613.88
5.4.150.0060.02113.78
5.4.140.0020.02312.93
5.4.130.0040.02112.99
5.4.120.0070.01912.93
5.4.110.0030.02213.14
5.4.100.0070.02112.96
5.4.90.0090.01713.00
5.4.80.0070.02013.01
5.4.70.0070.02113.01
5.4.60.0020.02413.04
5.4.50.0040.02212.99
5.4.40.0060.02012.90
5.4.30.0030.02213.01
5.4.20.0030.02312.89
5.4.10.0080.02613.02
5.4.00.0090.02112.81
5.3.290.0080.03012.54
5.3.280.0080.02412.45
5.3.270.0020.03412.47
5.3.260.0160.02112.41
5.3.250.0120.03212.29
5.3.240.0110.03312.42
5.3.230.0060.02612.36
5.3.220.0050.03012.33
5.3.210.0080.03312.45
5.3.200.0080.02312.39
5.3.190.0070.02712.44
5.3.180.0040.03112.39
5.3.170.0060.03012.44
5.3.160.0070.02712.43
5.3.150.0100.03312.50
5.3.140.0030.03012.53
5.3.130.0050.03212.50
5.3.120.0100.03712.44
5.3.110.0070.03012.39
5.3.100.0030.03012.06
5.3.90.0100.02112.11
5.3.80.0030.03012.12
5.3.70.0090.02612.05
5.3.60.0080.02312.15
5.3.50.0020.03012.08
5.3.40.0030.03012.08
5.3.30.0080.02812.07
5.3.20.0100.02411.93
5.3.10.0070.02711.94
5.3.00.0080.02511.83
5.2.170.0070.02210.68
5.2.160.0030.02310.66
5.2.150.0050.02210.66
5.2.140.0070.02010.68
5.2.130.0070.01810.56
5.2.120.0020.02510.57
5.2.110.0100.01710.56
5.2.100.0050.02110.61
5.2.90.0060.02110.66
5.2.80.0030.02510.59
5.2.70.0070.02310.66
5.2.60.0050.02310.56
5.2.50.0080.02010.52
5.2.40.0060.02110.47
5.2.30.0080.01810.50
5.2.20.0070.02410.49
5.2.10.0020.02510.44
5.2.00.0050.02310.42
5.1.60.0030.01710.13
5.1.50.0050.01710.12
5.1.40.0020.02210.12
5.1.30.0000.02310.23
5.1.20.0070.01810.26
5.1.10.0030.02210.04
5.1.00.0050.02010.12
5.0.50.0050.0159.28
5.0.40.0050.0159.25
5.0.30.0030.0239.16
5.0.20.0020.0179.14
5.0.10.0050.0139.09
5.0.00.0050.0229.11
4.4.90.0020.0127.98
4.4.80.0000.0198.04
4.4.70.0020.0137.99
4.4.60.0030.0117.96
4.4.50.0000.0157.96
4.4.40.0030.0187.96
4.4.30.0020.0127.97
4.4.20.0020.0148.06
4.4.10.0000.0157.99
4.4.00.0030.0198.04
4.3.110.0070.0108.01
4.3.100.0030.0128.00
4.3.90.0020.0137.97
4.3.80.0030.0187.93
4.3.70.0030.0127.97
4.3.60.0030.0147.98
4.3.50.0070.0107.95
4.3.40.0030.0227.97
4.3.30.0080.0137.35
4.3.20.0020.0127.29
4.3.10.0000.0147.32
4.3.00.0030.00813.09

preferences:
18.68 ms | 401 KiB | 5 Q