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) { if (isset($options[$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.01118.43
8.3.50.0040.01116.12
8.3.40.0090.00618.85
8.3.30.0070.00718.64
8.3.20.0040.00419.14
8.3.10.0080.00023.48
8.3.00.0030.00620.82
8.2.180.0180.00418.41
8.2.170.0070.00722.96
8.2.160.0220.00321.99
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0040.00422.10
8.2.120.0080.00026.35
8.2.110.0120.01520.96
8.2.100.0150.00017.88
8.2.90.0040.00419.34
8.2.80.0030.00618.05
8.2.70.0070.00317.88
8.2.60.0080.00018.05
8.2.50.0090.00018.10
8.2.40.0060.00322.38
8.2.30.0080.00021.14
8.2.20.0000.00718.09
8.2.10.0020.00518.15
8.2.00.0040.00418.27
8.1.280.0090.00625.92
8.1.270.0070.00024.02
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0100.00021.44
8.1.230.0080.00320.52
8.1.220.0080.00017.88
8.1.210.0040.00418.77
8.1.200.0090.00017.48
8.1.190.0040.00417.25
8.1.180.0040.00418.10
8.1.170.0080.00018.76
8.1.160.0040.00419.17
8.1.150.0040.00420.66
8.1.140.0030.00619.61
8.1.130.0000.00818.88
8.1.120.0040.00417.45
8.1.110.0050.00317.55
8.1.100.0000.00717.47
8.1.90.0000.00817.59
8.1.80.0000.00717.43
8.1.70.0000.00717.48
8.1.60.0080.00017.80
8.1.50.0050.00317.66
8.1.40.0030.00617.67
8.1.30.0030.00517.79
8.1.20.0080.00017.75
8.1.10.0040.00417.71
8.1.00.0040.00417.63
8.0.300.0050.00218.77
8.0.290.0080.00016.61
8.0.280.0030.00318.59
8.0.270.0070.00017.29
8.0.260.0030.00316.89
8.0.250.0030.00317.10
8.0.240.0040.00417.13
8.0.230.0040.00417.04
8.0.220.0000.00716.96
8.0.210.0000.00717.02
8.0.200.0000.00616.95
8.0.190.0040.00417.13
8.0.180.0050.00517.01
8.0.170.0000.00717.05
8.0.160.0070.00017.05
8.0.150.0030.00517.00
8.0.140.0040.00417.06
8.0.130.0050.00013.47
8.0.120.0040.00417.02
8.0.110.0000.00716.99
8.0.100.0030.00617.09
8.0.90.0050.00317.00
8.0.80.0100.00716.93
8.0.70.0040.00417.09
8.0.60.0040.00416.93
8.0.50.0050.00216.95
8.0.30.0070.00917.25
8.0.20.0100.01017.45
8.0.10.0060.00316.99
8.0.00.0120.00616.74
7.4.330.0050.00015.55
7.4.320.0030.00316.61
7.4.300.0060.00016.60
7.4.290.0030.00316.70
7.4.280.0080.00016.70
7.4.270.0050.00316.61
7.4.260.0000.00613.32
7.4.250.0030.00316.60
7.4.240.0040.00416.67
7.4.230.0030.00316.80
7.4.220.0090.01216.68
7.4.210.0070.01016.48
7.4.200.0040.00416.49
7.4.160.0100.00916.56
7.4.150.0110.00617.40
7.4.140.0110.00717.86
7.4.130.0210.00616.38
7.4.120.0100.01316.61
7.4.110.0130.00616.71
7.4.100.0090.00916.71
7.4.90.0150.00316.61
7.4.80.0230.00019.39
7.4.70.0100.00716.64
7.4.60.0140.00716.44
7.4.50.0000.01216.46
7.4.40.0030.01816.61
7.4.30.0100.01416.54
7.4.10.0090.01014.96
7.4.00.0070.01015.13
7.3.330.0000.00613.50
7.3.320.0050.00013.38
7.3.310.0040.00416.46
7.3.300.0040.00216.50
7.3.290.0070.00916.48
7.3.280.0080.00916.44
7.3.270.0050.01217.40
7.3.260.0110.00516.50
7.3.250.0090.01116.58
7.3.240.0060.01316.57
7.3.230.0060.02116.59
7.3.210.0150.00416.75
7.3.200.0140.00516.53
7.3.190.0070.01716.30
7.3.180.0080.00816.73
7.3.170.0130.00316.60
7.3.160.0060.00916.61
7.3.130.0080.00914.99
7.3.120.0110.00514.96
7.3.110.0080.00914.84
7.3.100.0050.01014.89
7.3.90.0130.00415.20
7.3.80.0060.00815.09
7.3.70.0100.00114.78
7.3.60.0080.00714.94
7.3.50.0080.00614.81
7.3.40.0070.00714.81
7.3.30.0060.00714.85
7.3.20.0030.00816.66
7.3.10.0080.00816.58
7.3.00.0090.00516.58
7.2.330.0030.01816.76
7.2.320.0130.00516.86
7.2.310.0190.00316.71
7.2.300.0130.00316.88
7.2.290.0110.01116.55
7.2.260.0070.01015.12
7.2.250.0080.00915.16
7.2.240.0070.00815.23
7.2.230.0060.01015.16
7.2.220.0100.00615.31
7.2.210.0060.01114.97
7.2.200.0060.00515.28
7.2.190.0020.01315.05
7.2.180.0040.00915.07
7.2.170.0030.01115.15
7.2.160.0040.00815.05
7.2.150.0020.01216.79
7.2.140.0090.00516.81
7.2.130.0050.01216.87
7.2.120.0090.00816.84
7.2.110.0070.01116.95
7.2.100.0090.00916.80
7.2.90.0100.00916.92
7.2.80.0090.01016.91
7.2.70.0050.00816.86
7.2.60.0040.01116.95
7.2.50.0090.00816.86
7.2.40.0060.00816.97
7.2.30.0080.00616.85
7.2.20.0070.00816.87
7.2.10.0070.00816.78
7.2.00.0100.00617.33
7.1.330.0050.00915.77
7.1.320.0080.00615.87
7.1.310.0050.00715.88
7.1.300.0030.00915.90
7.1.290.0020.01015.76
7.1.280.0070.00715.74
7.1.270.0050.00915.85
7.1.260.0030.01115.71
7.1.250.0100.00515.75
7.1.240.0050.00815.85
7.1.230.0020.00815.70
7.1.220.0090.00315.85
7.1.210.0040.00815.74
7.1.200.0050.00715.82
7.1.190.0070.00515.94
7.1.180.0040.01015.82
7.1.170.0020.01015.80
7.1.160.0050.00715.87
7.1.150.0050.00915.86
7.1.140.0070.00715.74
7.1.130.0030.01115.89
7.1.120.0040.00715.87
7.1.110.0020.01115.75
7.1.100.0050.00816.38
7.1.90.0060.00815.92
7.1.80.0030.00915.75
7.1.70.0050.00816.16
7.1.60.0620.00620.29
7.1.50.0100.00620.62
7.1.40.0080.00820.61
7.1.30.0080.00920.50
7.1.20.0300.00920.06
7.1.10.0050.00715.95
7.1.00.0040.00916.15
7.0.330.0060.00815.37
7.0.320.0040.00715.46
7.0.310.0030.01015.48
7.0.300.0070.00515.53
7.0.290.0050.00715.41
7.0.280.0030.00915.48
7.0.270.0040.00815.40
7.0.260.0030.01015.30
7.0.250.0070.00615.26
7.0.240.0050.00715.37
7.0.230.0020.01015.39
7.0.220.0040.00915.44
7.0.210.0030.00815.42
7.0.200.0410.00615.36
7.0.190.0430.00815.34
7.0.180.0060.00515.69
7.0.170.0280.00915.68
7.0.160.0230.00915.62
7.0.150.0260.00815.18
7.0.140.0090.00515.52
7.0.130.0040.00915.72
7.0.120.0230.00915.23
7.0.110.0060.00615.69
7.0.100.0010.00915.70
7.0.90.0050.00615.69
7.0.80.0030.00715.70
7.0.70.0040.00815.79
7.0.60.0060.00715.67
7.0.50.0070.00415.70
7.0.40.0040.00814.29
7.0.30.0050.00714.16
7.0.20.0030.00814.20
7.0.10.0060.00614.26
7.0.00.0050.00714.18
5.6.400.0060.00614.09
5.6.390.0060.00714.13
5.6.380.0080.00514.26
5.6.370.0050.00814.19
5.6.360.0050.00614.13
5.6.350.0040.00814.23
5.6.340.0050.00814.00
5.6.330.0040.00713.96
5.6.320.0050.00814.07
5.6.310.0010.01113.95
5.6.300.0100.00514.01
5.6.290.0060.00414.29
5.6.280.0050.01014.34
5.6.270.0110.00314.26
5.6.260.0080.00414.03
5.6.250.0010.01014.09
5.6.240.0030.00914.13
5.6.230.0050.00614.08
5.6.220.0090.00614.12
5.6.210.0070.00513.93
5.6.200.0060.00714.11
5.6.190.0090.00314.17
5.6.180.0040.00814.10
5.6.170.0050.00514.11
5.6.160.0060.00514.21
5.6.150.0060.00714.16
5.6.140.0030.01114.21
5.6.130.0040.00814.09
5.6.120.0060.00814.09
5.6.110.0010.01013.96
5.6.100.0050.00914.07
5.6.90.0050.00614.23
5.6.80.0050.00614.02
5.6.70.0050.00714.09
5.6.60.0040.00714.00
5.6.50.0020.00914.14
5.6.40.0110.00214.09
5.6.30.0050.00914.05
5.6.20.0050.01114.11
5.6.10.0040.01014.16
5.6.00.0030.00914.00

preferences:
79.97 ms | 401 KiB | 5 Q