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['min'], ['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.0090.01218.31
8.3.50.0120.00316.30
8.3.40.0140.00718.84
8.3.30.0130.00318.84
8.3.20.0080.00020.89
8.3.10.0000.00821.99
8.3.00.0080.00020.91
8.2.180.0140.00718.41
8.2.170.0150.00322.96
8.2.160.0100.00321.93
8.2.150.0080.00025.66
8.2.140.0040.00424.66
8.2.130.0050.00322.26
8.2.120.0080.00026.35
8.2.110.0080.00320.52
8.2.100.0070.00417.97
8.2.90.0000.00819.30
8.2.80.0040.00418.05
8.2.70.0030.00617.75
8.2.60.0080.00017.91
8.2.50.0000.01018.10
8.2.40.0030.00622.19
8.2.30.0080.00021.16
8.2.20.0050.00318.09
8.2.10.0070.00018.27
8.2.00.0060.00318.12
8.1.280.0110.00725.92
8.1.270.0050.00323.75
8.1.260.0000.00826.35
8.1.250.0000.00728.09
8.1.240.0000.01022.52
8.1.230.0060.00619.29
8.1.220.0000.00717.78
8.1.210.0000.00818.77
8.1.200.0030.00817.48
8.1.190.0000.00817.23
8.1.180.0060.00318.10
8.1.170.0060.00318.63
8.1.160.0040.00419.01
8.1.150.0050.00320.61
8.1.140.0100.00019.67
8.1.130.0050.00318.99
8.1.120.0000.00717.59
8.1.110.0000.00817.50
8.1.100.0040.00417.59
8.1.90.0000.00917.51
8.1.80.0070.00017.51
8.1.70.0030.00617.47
8.1.60.0040.00417.77
8.1.50.0000.00817.70
8.1.40.0000.00817.73
8.1.30.0030.00617.82
8.1.20.0000.00817.66
8.1.10.0080.00017.72
8.1.00.0000.00817.69
8.0.300.0040.00418.77
8.0.290.0040.00417.00
8.0.280.0070.00018.64
8.0.270.0040.00417.45
8.0.260.0000.00717.04
8.0.250.0000.00717.19
8.0.240.0040.00417.06
8.0.230.0030.00317.05
8.0.220.0070.00017.07
8.0.210.0070.00017.06
8.0.200.0050.00217.17
8.0.190.0000.00817.14
8.0.180.0060.00317.09
8.0.170.0000.00717.10
8.0.160.0030.00717.06
8.0.150.0040.00417.16
8.0.140.0040.00417.05
8.0.130.0030.00313.55
8.0.120.0040.00417.17
8.0.110.0040.00417.06
8.0.100.0040.00417.16
8.0.90.0030.00516.95
8.0.80.0080.00817.02
8.0.70.0000.00817.06
8.0.60.0070.00016.93
8.0.50.0000.00717.07
8.0.30.0120.00817.23
8.0.20.0090.01117.40
8.0.10.0040.00417.17
8.0.00.0060.01217.00
7.4.330.0030.00315.55
7.4.320.0000.00616.67
7.4.300.0060.00016.66
7.4.290.0070.00016.57
7.4.280.0000.00816.64
7.4.270.0050.00216.45
7.4.260.0030.00313.36
7.4.250.0040.00416.54
7.4.240.0070.00016.58
7.4.230.0000.00716.50
7.4.220.0030.01616.75
7.4.210.0060.00916.71
7.4.200.0000.00716.70
7.4.160.0060.01116.50
7.4.150.0090.00917.40
7.4.140.0110.00917.86
7.4.130.0090.01616.63
7.4.120.0120.01016.71
7.4.110.0060.01216.68
7.4.100.0130.00616.64
7.4.90.0110.00816.81
7.4.80.0070.01619.39
7.4.70.0090.00816.65
7.4.60.0100.00716.66
7.4.50.0070.01016.52
7.4.40.0000.01616.58
7.4.30.0040.01516.52
7.4.00.0030.01315.36
7.3.330.0050.00013.52
7.3.320.0050.00013.35
7.3.310.0030.00316.34
7.3.300.0030.00316.40
7.3.290.0100.00516.47
7.3.280.0090.00816.53
7.3.270.0070.01017.40
7.3.260.0120.00616.54
7.3.250.0110.01316.65
7.3.240.0120.00616.74
7.3.230.0130.01516.50
7.3.210.0090.00916.52
7.3.200.0100.00716.45
7.3.190.0130.01216.57
7.3.180.0060.00916.79
7.3.170.0030.01416.56
7.3.160.0110.01116.54
7.2.330.0070.01016.88
7.2.320.0060.01217.01
7.2.310.0060.01216.86
7.2.300.0100.00716.94
7.2.290.0090.01116.79
7.2.60.0000.01516.99
7.2.00.0040.01119.59
7.1.200.0040.01115.73
7.1.100.0090.00918.29
7.1.70.0000.00717.09
7.1.60.0170.00734.93
7.1.50.1130.01033.12
7.1.40.0630.01332.83
7.1.30.0730.00732.95
7.1.20.0130.01334.78
7.1.10.0030.00716.73
7.1.00.0030.00716.85
7.0.200.0030.00716.65
7.0.190.1000.00716.87
7.0.180.0600.01014.48
7.0.170.0530.01016.24
7.0.160.0030.01316.19
7.0.150.0000.01016.25
7.0.140.0030.01016.49
7.0.130.0030.01016.58
7.0.120.0130.00016.50
7.0.110.0100.00316.31
7.0.100.0030.01016.52
7.0.90.0070.00716.42
7.0.80.0030.01016.48
7.0.70.0070.00716.27
7.0.60.0070.00316.32
7.0.50.0030.01016.31
7.0.40.0030.00716.54
7.0.30.0000.01016.57
7.0.20.0000.01016.48
7.0.10.0070.00316.39
7.0.00.0030.00716.35

preferences:
41.65 ms | 400 KiB | 5 Q