3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class Filter { abstract public static function check($value, array $options = array()); } final class IntFilter { public static function check($value, array $options = array()) { return $value; } } final class StringFilter { public static function check($value, array $options = array()) { if (false === is_string($value)) { return false; } if (false !== ($options['trim'] ?? true)) { $value = trim($value); } $length = mb_strlen($value, '8bit'); if ((false === ($options['empty'] ?? true)) && (0 === $length)) { return false; } foreach (['min', 'max'] as $name) { $optionLength = IntFilter::check($options[$name], ['min' => 1]); if (('min' === $name && $length < $optionLength) || ('max' === $name && $length > $optionLength)) { return false; } } foreach (['startsWith', 'endsWith'] as $name) { if (isset($options[$name])) { $needle = StringFilter::check($options[$name]); if (false === self::$name($value, $needle)) { return false; } } } return $value; } private static function startsWith($haystack, $needle) { return $haystack[0] === $needle[0] ? strncmp($haystack, $needle, mb_strlen($needle, '8bit')) === 0 : false; } private static function endsWith($haystack, $needle) { return self::startsWith(mb_substr($haystack, -mb_strlen($needle, '8bit')), $needle); } } var_dump(StringFilter::check(' r a ', ['min' => 4])); var_dump(StringFilter::check(' r a ', ['max' => 4])); var_dump(StringFilter::check(' r a ', ['min' => 4, 'max' => 4])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'r'])); var_dump(StringFilter::check(' r a ', ['endsWith' => 'a'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'r', 'endsWith' => 'a'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'r at'])); var_dump(StringFilter::check(' r a ', ['endsWith' => 'r at'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'r at', 'endsWith' => 'r at'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'z'])); var_dump(StringFilter::check(' r a ', ['endsWith' => 'z'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'r', 'endsWith' => 'z'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'z', 'endsWith' => 'a'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'z', 'endsWith' => 'y']));

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.60.0070.00718.43
8.3.50.0040.01216.39
8.3.40.0130.00918.79
8.3.30.0090.00618.67
8.3.20.0050.00320.75
8.3.10.0080.00021.95
8.3.00.0000.00820.77
8.2.180.0140.00718.41
8.2.170.0090.00622.96
8.2.160.0000.01422.31
8.2.150.0000.00825.66
8.2.140.0000.00724.66
8.2.130.0040.00422.12
8.2.120.0000.00726.35
8.2.110.0030.00620.31
8.2.100.0120.00018.03
8.2.90.0050.00319.30
8.2.80.0080.00017.97
8.2.70.0090.00017.88
8.2.60.0080.00018.18
8.2.50.0030.00618.10
8.2.40.0040.00422.27
8.2.30.0000.00821.10
8.2.20.0070.00018.12
8.2.10.0000.00718.29
8.2.00.0000.00818.14
8.1.280.0180.00425.92
8.1.270.0050.00323.84
8.1.260.0000.00726.35
8.1.250.0040.00428.09
8.1.240.0100.00022.62
8.1.230.0110.00019.14
8.1.220.0090.00017.91
8.1.210.0030.00618.77
8.1.200.0000.00917.35
8.1.190.0000.00817.35
8.1.180.0080.00018.10
8.1.170.0030.00618.59
8.1.160.0000.00719.09
8.1.150.0080.00020.61
8.1.140.0080.00419.59
8.1.130.0000.00719.02
8.1.120.0070.00017.52
8.1.110.0060.00317.41
8.1.100.0000.00817.61
8.1.90.0000.00817.59
8.1.80.0050.00217.47
8.1.70.0070.00017.57
8.1.60.0000.00817.74
8.1.50.0040.00417.57
8.1.40.0000.00917.63
8.1.30.0030.00517.71
8.1.20.0070.00017.79
8.1.10.0040.00417.73
8.1.00.0040.00417.66
8.0.300.0040.00418.77
8.0.290.0040.00416.88
8.0.280.0000.00718.60
8.0.270.0000.00817.35
8.0.260.0000.00717.05
8.0.250.0070.00017.15
8.0.240.0000.00917.06
8.0.230.0000.00717.17
8.0.220.0050.00316.99
8.0.210.0000.00717.07
8.0.200.0030.00317.18
8.0.190.0000.00817.21
8.0.180.0070.00317.20
8.0.170.0040.00417.16
8.0.160.0000.00917.11
8.0.150.0030.00517.10
8.0.140.0040.00417.09
8.0.130.0030.00313.60
8.0.120.0000.00717.04
8.0.110.0040.00416.98
8.0.100.0040.00417.00
8.0.90.0040.00417.00
8.0.80.0100.01017.09
8.0.70.0000.00817.08
8.0.60.0000.00817.10
8.0.50.0040.00417.18
8.0.30.0120.00617.38
8.0.20.0130.00717.40
8.0.10.0080.00017.04
8.0.00.0090.00916.87
7.4.330.0060.00015.55
7.4.320.0030.00316.50
7.4.300.0000.00616.57
7.4.290.0000.00716.72
7.4.280.0000.00816.54
7.4.270.0030.00316.62
7.4.260.0030.00313.32
7.4.250.0070.00016.63
7.4.240.0000.00816.59
7.4.230.0030.00316.39
7.4.220.0190.00016.65
7.4.210.0090.00616.65
7.4.200.0070.00016.49
7.4.160.0090.00816.68
7.4.150.0090.00917.40
7.4.140.0120.00817.86
7.4.130.0130.01316.68
7.4.120.0090.01016.67
7.4.110.0120.00616.82
7.4.100.0060.01716.56
7.4.90.0070.01016.60
7.4.80.0200.00319.39
7.4.70.0100.00716.56
7.4.60.0100.00716.57
7.4.50.0070.01016.47
7.4.40.0120.00616.69
7.4.30.0170.00716.71
7.4.00.0150.00314.81
7.3.330.0050.00013.34
7.3.320.0050.00013.34
7.3.310.0070.00016.61
7.3.300.0000.00716.49
7.3.290.0090.00616.51
7.3.280.0090.01016.49
7.3.270.0130.01317.40
7.3.260.0110.00916.68
7.3.250.0080.01216.64
7.3.240.0100.00716.49
7.3.230.0100.00516.53
7.3.210.0080.00816.59
7.3.200.0080.00816.54
7.3.190.0030.02016.73
7.3.180.0030.01316.77
7.3.170.0130.00516.74
7.3.160.0150.00916.59
7.2.330.0040.01416.92
7.2.320.0090.00916.87
7.2.310.0090.00916.94
7.2.300.0000.01716.77
7.2.290.0190.00316.71
7.2.60.0060.00916.33
7.1.200.0000.01516.02
7.1.100.0130.00618.01
7.1.70.0030.00717.19
7.1.60.0100.01735.19
7.1.50.0130.01034.67
7.1.40.0200.00734.64
7.1.30.0170.01034.57
7.1.20.0130.01334.52
7.1.10.0030.01016.68
7.1.00.0030.01016.91
7.0.200.0970.00014.93
7.0.190.0000.01016.69
7.0.180.0900.01016.32
7.0.170.0070.00316.23
7.0.160.0000.01316.02
7.0.150.0100.00016.30
7.0.140.0070.00316.29
7.0.130.0000.01316.46
7.0.120.0100.00316.63
7.0.110.0070.00316.56
7.0.100.0000.01016.45
7.0.90.0070.00316.27
7.0.80.0070.00316.57
7.0.70.0070.00316.49
7.0.60.0030.00715.99
7.0.50.0000.01016.48
7.0.40.0000.01016.57
7.0.30.0030.00716.69
7.0.20.0070.00716.51
7.0.10.0070.00716.38
7.0.00.0030.00716.23

preferences:
61.57 ms | 400 KiB | 5 Q