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 (['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 ', ['startsWith' => 'r'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'z'])); var_dump(StringFilter::check(' r a ', ['endsWith' => 'a'])); var_dump(StringFilter::check(' r a ', ['endsWith' => 'z'])); var_dump(StringFilter::check(' r a ', ['startsWith' => 'r', 'endsWith' => 'a'])); 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.43
8.3.50.0140.00416.58
8.3.40.0040.01118.85
8.3.30.0140.00018.85
8.3.20.0040.00419.01
8.3.10.0050.00321.87
8.3.00.0030.00620.94
8.2.180.0160.00618.30
8.2.170.0110.00722.96
8.2.160.0030.01022.26
8.2.150.0040.00725.66
8.2.140.0030.00524.66
8.2.130.0060.00322.08
8.2.120.0040.00426.35
8.2.110.0060.00620.53
8.2.100.0040.00817.69
8.2.90.0000.00819.36
8.2.80.0050.00318.05
8.2.70.0040.00417.50
8.2.60.0030.00518.04
8.2.50.0090.00018.10
8.2.40.0040.00420.61
8.2.30.0050.00319.23
8.2.20.0000.00718.16
8.2.10.0000.00718.08
8.2.00.0020.00518.03
8.1.280.0120.00625.92
8.1.270.0040.00423.96
8.1.260.0000.00826.35
8.1.250.0050.00228.09
8.1.240.0060.00322.47
8.1.230.0080.00319.10
8.1.220.0040.00417.80
8.1.210.0030.00618.77
8.1.200.0030.00617.25
8.1.190.0000.00817.10
8.1.180.0090.00018.10
8.1.170.0040.00418.61
8.1.160.0030.00519.02
8.1.150.0040.00420.55
8.1.140.0070.00419.61
8.1.130.0040.00418.80
8.1.120.0040.00417.48
8.1.110.0060.00317.50
8.1.100.0000.00817.44
8.1.90.0040.00517.42
8.1.80.0000.00717.41
8.1.70.0070.00017.41
8.1.60.0030.00617.69
8.1.50.0060.00317.65
8.1.40.0090.00017.60
8.1.30.0040.00417.74
8.1.20.0050.00317.67
8.1.10.0000.00817.58
8.1.00.0050.00317.49
8.0.300.0090.00018.77
8.0.290.0060.00316.75
8.0.280.0000.00718.55
8.0.270.0000.00717.27
8.0.260.0030.00318.54
8.0.250.0000.00717.05
8.0.240.0050.00317.05
8.0.230.0030.00317.04
8.0.220.0070.00016.98
8.0.210.0000.00717.00
8.0.200.0030.00317.02
8.0.190.0030.00616.90
8.0.180.0030.00617.02
8.0.170.0030.00517.04
8.0.160.0050.00517.06
8.0.150.0040.00417.04
8.0.140.0000.00716.86
8.0.130.0030.00313.39
8.0.120.0070.00016.86
8.0.110.0000.00717.05
8.0.100.0000.00716.85
8.0.90.0040.00416.98
8.0.80.0030.01216.89
8.0.70.0040.00416.87
8.0.60.0000.00716.88
8.0.50.0030.00516.94
8.0.30.0100.00917.21
8.0.20.0110.00817.40
8.0.10.0070.00016.93
8.0.00.0180.00016.66
7.4.330.0000.00615.55
7.4.320.0070.00016.60
7.4.300.0060.00016.60
7.4.290.0040.00416.63
7.4.280.0000.00716.63
7.4.270.0000.00816.50
7.4.260.0000.00513.18
7.4.250.0070.00016.41
7.4.240.0070.00016.63
7.4.230.0000.00716.38
7.4.220.0090.00916.64
7.4.210.0090.00616.41
7.4.200.0040.00416.74
7.4.160.0070.01016.67
7.4.150.0160.00317.40
7.4.140.0120.01317.86
7.4.130.0140.01116.43
7.4.120.0110.00716.61
7.4.110.0110.01116.77
7.4.100.0140.00416.59
7.4.90.0030.01716.64
7.4.80.0130.01019.39
7.4.70.0060.01016.63
7.4.60.0100.00716.59
7.4.50.0060.01216.50
7.4.40.0080.01216.54
7.4.30.0150.00916.62
7.4.00.0100.00514.82
7.3.330.0020.00213.42
7.3.320.0000.00513.23
7.3.310.0070.00016.45
7.3.300.0030.00316.34
7.3.290.0060.01116.38
7.3.280.0070.00916.38
7.3.270.0070.01017.40
7.3.260.0110.00816.33
7.3.250.0170.00516.29
7.3.240.0120.00916.57
7.3.230.0130.00716.43
7.3.210.0230.00316.61
7.3.200.0070.01716.64
7.3.190.0090.01116.49
7.3.180.0140.00416.47
7.3.170.0040.01216.60
7.3.160.0070.00716.60
7.3.10.0070.00716.61
7.3.00.0130.00016.47
7.2.330.0040.01416.82
7.2.320.0110.00616.65
7.2.310.0060.01016.77
7.2.300.0110.00616.71
7.2.290.0090.00916.83
7.2.130.0000.01216.71
7.2.120.0090.00317.05
7.2.110.0030.01016.90
7.2.100.0060.00916.95
7.2.90.0000.01416.77
7.2.80.0050.00816.81
7.2.70.0060.00616.88
7.2.60.0070.00616.95
7.2.50.0060.00916.88
7.2.40.0000.01416.75
7.2.30.0070.00316.98
7.2.20.0070.00717.02
7.2.10.0030.00717.00
7.2.00.0030.01218.31
7.1.250.0030.00615.93
7.1.200.0070.00715.87
7.1.100.0050.00518.22
7.1.70.0040.00417.34
7.1.60.0100.01335.22
7.1.50.0130.01034.93
7.1.40.0100.01334.45
7.1.30.0100.01734.48
7.1.20.0130.01334.64
7.1.10.0070.00716.88
7.1.00.0030.00716.79
7.0.200.0100.00016.91
7.0.190.0030.00716.86
7.0.180.0030.00716.37
7.0.170.0030.01016.34
7.0.160.0000.01016.30
7.0.150.0030.01016.36
7.0.140.0000.01016.58
7.0.130.0000.01016.62
7.0.120.0030.00716.54
7.0.110.0070.00316.56
7.0.100.0030.01016.52
7.0.90.0000.01016.26
7.0.80.0070.00316.57
7.0.70.0030.00716.30
7.0.60.0030.00716.21
7.0.50.0000.01316.36
7.0.40.0070.00716.55
7.0.30.0000.01316.66
7.0.20.0030.01016.34
7.0.10.0030.01016.17
7.0.00.0100.00716.37

preferences:
44.55 ms | 400 KiB | 5 Q