3v4l.org

run code in 300+ PHP versions simultaneously
<?php class ValidationException extends \Exception { } interface Validator { /** * @param mixed $data * * @throws ValidationException */ public function validate($data); } class ValidatorComposite { /** * @var Validator[] */ protected $validators; public function addValidator(Validator $validator) { $this->validators[] = $validator; } public function validate($data) { $exceptions = []; foreach ($this->validators as $validator) { try { $validator->validate($data); } catch (ValidationException $e) { $exceptions[] = $e->getMessage(); } /** Now you have a list of exceptions that were thrown in $exceptions **/ return $exceptions; } } } class ArrayKeyExistsValidator implements Validator { protected $requiredKeys = []; public function __construct(array $requiredKeys) { $this->requiredKeys = $requiredKeys; } public function validate($data) { if (!is_array($data)) { // either try to convert to array or throw exception } foreach ($this->requiredKeys as $requiredKey) { /** recursively search your array for each key**/ // I'm doing non recursively here if (!array_key_exists($requiredKey, $data)) { throw new ValidationException( sprintf('Key: "%s" not found in array: "%s"', $requiredKey, print_r($data, true)) ); } } } } // Object Usage $composite = new ValidatorComposite; $validator = new ArrayKeyExistsValidator(array('key1', 'key2')); $composite->addValidator($validator); $dataToValidate = array('LOL', 'key1', 'thereIsntAKey2'); $composite->validate($dataToValidate);

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.00718.43
8.3.60.0060.00918.68
8.3.50.0110.00821.09
8.3.40.0120.00318.96
8.3.30.0060.00919.07
8.3.20.0050.00320.29
8.3.10.0040.00423.65
8.3.00.0080.00022.52
8.2.190.0140.00716.75
8.2.180.0110.00718.66
8.2.170.0090.00922.96
8.2.160.0140.00020.34
8.2.150.0100.00724.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0060.00317.75
8.2.110.0100.00020.94
8.2.100.0080.00417.75
8.2.90.0040.00419.21
8.2.80.0080.00017.97
8.2.70.0090.00017.63
8.2.60.0040.00417.93
8.2.50.0000.00818.07
8.2.40.0040.00421.25
8.2.30.0040.00418.02
8.2.20.0000.00817.79
8.2.10.0040.00418.05
8.2.00.0000.00718.04
8.1.280.0100.00725.92
8.1.270.0030.00620.08
8.1.260.0040.00426.35
8.1.250.0000.00828.09
8.1.240.0060.00322.22
8.1.230.0070.00422.24
8.1.220.0040.00417.79
8.1.210.0050.00318.77
8.1.200.0030.00717.48
8.1.190.0060.00317.35
8.1.180.0040.00418.10
8.1.170.0040.00418.72
8.1.160.0030.00622.04
8.1.150.0040.00418.88
8.1.140.0040.00417.50
8.1.130.0040.00417.71
8.1.120.0070.00017.52
8.1.110.0000.00717.43
8.1.100.0050.00317.48
8.1.90.0000.00917.46
8.1.80.0050.00317.44
8.1.70.0030.00317.52
8.1.60.0000.00817.54
8.1.50.0070.00317.44
8.1.40.0040.00417.50
8.1.30.0000.00817.59
8.1.20.0030.00617.69
8.1.10.0000.00817.62
8.1.00.0000.00817.55
8.0.300.0040.00418.77
8.0.290.0070.00016.88
8.0.280.0050.00318.50
8.0.270.0000.00717.19
8.0.260.0060.00017.29
8.0.250.0030.00316.92
8.0.240.0000.00717.04
8.0.230.0000.00717.02
8.0.220.0050.00317.02
8.0.210.0000.00716.88
8.0.200.0000.00716.93
8.0.190.0080.00017.05
8.0.180.0040.00417.02
8.0.170.0000.00816.88
8.0.160.0040.00417.00
8.0.150.0070.00016.90
8.0.140.0000.00716.97
8.0.130.0000.00613.46
8.0.120.0040.00416.93
8.0.110.0000.00816.89
8.0.100.0000.00716.85
8.0.90.0000.00716.83
8.0.80.0060.00916.94
8.0.70.0050.00316.84
8.0.60.0000.00717.02
8.0.50.0000.00816.93
8.0.30.0150.00717.08
8.0.20.0060.01317.40
8.0.10.0040.00417.05
8.0.00.0110.00816.84
7.4.330.0050.00015.08
7.4.320.0030.00316.48
7.4.300.0000.00616.54
7.4.290.0030.00316.50
7.4.280.0070.00316.61
7.4.270.0000.00716.46
7.4.260.0000.00716.59
7.4.250.0000.00816.48
7.4.240.0030.00416.57
7.4.230.0030.00316.27
7.4.220.0170.01416.55
7.4.210.0070.01016.42
7.4.200.0040.00416.73
7.4.160.0080.00816.64
7.4.150.0110.00817.40
7.4.140.0110.00917.86
7.4.130.0080.01016.58
7.4.120.0120.00716.47
7.4.110.0060.01016.71
7.4.100.0060.01916.49
7.4.90.0090.00916.59
7.4.80.0030.01819.39
7.4.70.0090.00916.43
7.4.60.0090.00616.54
7.4.50.0000.00516.54
7.4.40.0120.00616.66
7.4.30.0030.01316.44
7.4.00.0030.00915.20
7.3.330.0030.00313.36
7.3.320.0040.00413.26
7.3.310.0070.00016.40
7.3.300.0030.00316.23
7.3.290.0100.00716.32
7.3.280.0100.00516.40
7.3.270.0170.00417.40
7.3.260.0120.01216.38
7.3.250.0090.00816.44
7.3.240.0110.00516.41
7.3.230.0120.00616.58
7.3.210.0000.01716.59
7.3.200.0100.00716.46
7.3.190.0120.00916.39
7.3.180.0100.00716.57
7.3.170.0060.01016.61
7.3.160.0030.01716.36
7.2.330.0030.01616.80
7.2.320.0100.01016.81
7.2.310.0030.01316.71
7.2.300.0060.01216.91
7.2.290.0100.00716.57
7.2.60.0040.00716.75
7.2.00.0070.00719.16
7.1.200.0000.01415.64
7.1.100.0000.01017.83
7.1.70.0000.00917.20
7.1.60.0110.00017.17
7.1.50.0070.01516.89
7.1.00.0030.08022.32
7.0.200.0100.00716.92
7.0.60.0070.07319.93
7.0.50.0030.06318.00
7.0.40.0070.04320.14
7.0.30.0270.04020.07
7.0.20.0430.07020.22
7.0.10.0070.08020.23
7.0.00.0070.08720.22
5.6.280.0070.06021.14
5.6.210.0070.07320.55
5.6.200.0030.08718.17
5.6.190.0030.06020.63
5.6.180.0570.06320.64
5.6.170.0430.06720.56
5.6.160.0100.06020.48
5.6.150.0000.05718.16
5.6.140.0070.07718.25
5.6.130.0200.06018.14
5.6.120.0070.07021.00
5.6.110.0100.08320.99
5.6.100.0100.03321.15
5.6.90.0030.07020.96
5.6.80.0030.03720.53
5.5.350.0070.07720.34
5.5.340.0030.05018.05
5.5.330.0030.08020.27
5.5.320.0070.08020.30
5.5.310.0300.08020.42
5.5.300.0070.08018.08
5.5.290.0070.09017.96
5.5.280.0070.06720.89
5.5.270.0200.07020.82
5.5.260.0100.08020.90
5.5.250.0170.07320.68
5.5.240.0230.08020.25
5.4.450.0700.06319.45
5.4.440.0170.06019.48
5.4.430.0400.06019.60
5.4.420.0330.06019.42
5.4.410.0170.06319.45
5.4.400.0300.04719.13
5.4.390.0400.05718.98
5.4.380.0430.05018.88
5.4.370.0230.06318.98
5.4.360.0200.06018.84
5.4.350.0300.05719.29
5.4.340.0270.06018.98
5.4.320.0370.07019.16
5.4.310.0200.05019.13
5.4.300.0130.06018.84
5.4.290.0200.05318.86
5.4.280.0530.05719.15
5.4.270.0170.06319.26
5.4.260.0200.05719.28
5.4.250.0400.06719.29
5.4.240.0230.05719.00
5.4.230.0400.05319.29
5.4.220.0500.05019.11
5.4.210.0230.06019.08
5.4.200.0270.06716.96
5.4.190.0270.04718.99
5.4.180.0100.06319.34
5.4.170.0230.06018.88
5.4.160.0830.06719.27
5.4.150.0330.05319.08
5.4.140.0300.05716.64
5.4.130.0200.05016.41
5.4.120.0200.04316.42
5.4.110.0170.05716.41
5.4.100.0300.04016.60
5.4.90.0270.05016.49
5.4.80.0200.05716.62
5.4.70.0270.05016.59
5.4.60.0230.05016.37
5.4.50.0230.05016.53
5.4.40.0270.05016.47
5.4.30.0230.05716.36
5.4.20.0330.05316.29
5.4.10.0200.05016.40
5.4.00.0570.06016.18
5.3.290.0270.05714.64
5.3.280.0430.06014.75
5.3.270.0400.05014.75
5.3.260.0100.06014.76
5.3.250.0230.05014.59
5.3.240.0270.05314.54
5.3.230.0400.06014.69
5.3.220.0300.05314.69
5.3.210.0370.04314.66
5.3.200.0170.05714.55
5.3.190.0170.06014.65
5.3.180.0300.04714.78
5.3.170.0330.04314.63
5.3.160.0370.04714.78
5.3.150.0200.05014.54
5.3.140.0230.05714.54
5.3.130.0270.04714.64
5.3.120.0130.05714.77
5.3.110.0130.05314.77
5.3.100.0170.05314.02
5.3.90.0170.05714.15
5.3.80.0170.05014.24
5.3.70.0370.05313.96
5.3.60.0270.04313.98
5.3.50.0130.05714.03
5.3.40.0530.06014.07
5.3.30.0330.05714.07
5.3.20.0300.04713.67
5.3.10.0270.04313.80
5.3.00.0230.05313.77
5.2.170.0300.05711.23
5.2.160.0230.03711.39
5.2.150.0130.04711.07
5.2.140.0200.04011.08
5.2.130.0170.04011.12
5.2.120.0370.04311.12
5.2.110.0170.03711.12
5.2.100.0170.04310.97
5.2.90.0170.04011.03
5.2.80.0200.04011.11
5.2.70.0200.04011.19
5.2.60.0130.04010.93
5.2.50.0230.03711.26
5.2.40.0230.04010.98
5.2.30.0030.05010.89
5.2.20.0100.04710.88
5.2.10.0230.04710.80
5.2.00.0300.03010.74
5.1.60.0170.04310.24
5.1.50.0300.03710.07
5.1.40.0200.03010.07
5.1.30.0030.04310.26
5.1.20.0030.04310.38
5.1.10.0200.03010.17
5.1.00.0100.03310.17
5.0.50.0100.0278.61
5.0.40.0100.0278.35
5.0.30.0200.0408.13
5.0.20.0100.0238.14
5.0.10.0070.0278.11
5.0.00.0070.0608.10
4.4.90.0070.0275.84
4.4.80.0100.0205.87
4.4.70.0070.0235.92
4.4.60.0070.0275.83
4.4.50.0100.0205.83
4.4.40.0130.0305.87
4.4.30.0070.0235.83
4.4.20.0130.0205.90
4.4.10.0170.0175.92
4.4.00.0730.0375.82
4.3.110.0300.0135.69
4.3.100.0270.0205.73
4.3.90.0100.0205.76
4.3.80.0100.0335.83
4.3.70.0100.0235.78
4.3.60.0200.0235.75
4.3.50.0170.0175.76
4.3.40.0400.0435.70
4.3.30.0200.0274.45
4.3.20.0170.0274.41
4.3.10.0130.0274.40
4.3.00.0100.0207.21

preferences:
60.41 ms | 401 KiB | 5 Q