3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * @param integer $type Constant like INPUT_XXX * @param array $default Default structure of the specified super global var. * Following bitmasks are available: * + FILTER_STRUCT_FORCE_ARRAY - Force 1D array. * + FILTER_STRUCT_TRIM - Set trimmed string. * + FILTER_STRUCT_FULL_TRIM - Trim including full-width and no-break space. * @return string The value of the filtered super global var. * @see http://qiita.com/items/c39b9ee695a5c2e74627 */ define('FILTER_STRUCT_FORCE_ARRAY', 1); define('FILTER_STRUCT_TRIM', 2); define('FILTER_STRUCT_FULL_TRIM', 4); function filter_struct_utf8($type, array $default) { static $is_recursive_static = false; $is_recursive = $is_recursive_static; if (!$is_recursive) { $types = array( INPUT_GET => $_GET, INPUT_POST => $_POST, INPUT_COOKIE => $_COOKIE, INPUT_REQUEST => $_REQUEST, INPUT_ENV => $_ENV, INPUT_SERVER => $_SERVER, ); $type = (int)$type; if (!isset($types[$type])) { throw new LogicException('unknown super global var type'); } $var = $types[$type]; $is_recursive_static = true; } else { $var = $type; } $trim_chars = "\0\x20\x09\x0a\x0d\x0b"; $full_trim_chars = "{$trim_chars}\xc2\xa0\xe3\x80\x80"; $trim_pattern = "/\A[{$trim_chars}]++|[{$trim_chars}]++\z/u"; $full_trim_pattern = "/\A[{$full_trim_chars}]++|[{$full_trim_chars}]++\z/u"; $ret = array(); foreach ($default as $key => $value) { if (is_int($value) && !($value & ( FILTER_STRUCT_FORCE_ARRAY | FILTER_STRUCT_FULL_TRIM | FILTER_STRUCT_TRIM ))) { if (!$is_recursive) { $is_recursive_static = false; } throw new LogicException('unknown bitmask'); } if (is_int($value) && $value & FILTER_STRUCT_FORCE_ARRAY) { $tmp = array(); if (isset($var[$key])) { foreach ((array)$var[$key] as $k => $v) { if (!preg_match('//u', $k)) { continue; } $value &= FILTER_STRUCT_FULL_TRIM | FILTER_STRUCT_TRIM; $tmp += array($k => $value ? $value : ''); } } $value = $tmp; } if (isset($var[$key]) && is_array($value)) { $ret[$key] = filter_struct_utf8($var[$key], $value); } elseif (!isset($var[$key]) || is_array($var[$key])) { $ret[$key] = is_int($value) ? '' : $value; } else { if (!isset($var[$key]) || is_array($var[$key])) { $var[$key] = null; } elseif (is_int($value) && $value & FILTER_STRUCT_FULL_TRIM) { $var[$key] = preg_replace($full_trim_pattern, '', $var[$key]); } elseif (is_int($value) && $value & FILTER_STRUCT_TRIM) { $var[$key] = preg_replace($trim_pattern, '', $var[$key]); } else { $var[$key] = preg_replace('//u', '', $var[$key]); } if ($var[$key] === null) { $var[$key] = is_int($value) ? '' : $value; } $ret[$key] = $var[$key]; } } if (!$is_recursive) { $is_recursive_static = false; } return $ret; } $_POST['name'] = array( 'hahaha' => 'I am an array', ); $_POST['age'] = '  20 '; $_POST['gender'] = 'male'; $_POST['options'] = array( 'a' => array('hahaha' => 'This is an invalid option'), 'b' => ' hoge hoge ', 'c' => array('hahaha' => 'This is an invalid option'), 'd' => "\x0a\x0a\x0a This is invalid encoding value", "\x0a\x0a\x0a" => 'This is invalid encoding key', ); extract(filter_struct_utf8(INPUT_POST, array( 'name' => '', 'age' => FILTER_STRUCT_FULL_TRIM, 'email' => '', 'gender' => '', 'options' => FILTER_STRUCT_FORCE_ARRAY | FILTER_STRUCT_TRIM, ))); var_dump($name, $age, $email, $gender, $options);

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.0110.01118.43
8.3.50.0130.00721.27
8.3.40.0120.00318.97
8.3.30.0090.00619.22
8.3.20.0050.00220.16
8.3.10.0000.00822.09
8.3.00.0080.00022.41
8.2.180.0120.00416.75
8.2.170.0140.00722.96
8.2.160.0030.01019.20
8.2.150.0080.00024.18
8.2.140.0120.00324.66
8.2.130.0070.00726.16
8.2.120.0000.00819.66
8.2.110.0070.00320.93
8.2.100.0070.00417.97
8.2.90.0030.00619.17
8.2.80.0090.00017.97
8.2.70.0080.00017.63
8.2.60.0000.00817.93
8.2.50.0030.00718.10
8.2.40.0050.00320.42
8.2.30.0060.00618.25
8.2.20.0040.00418.04
8.2.10.0090.00017.85
8.2.00.0000.00717.81
8.1.280.0110.00725.92
8.1.270.0030.00518.58
8.1.260.0070.00026.35
8.1.250.0040.00428.09
8.1.240.0090.00021.20
8.1.230.0080.00317.83
8.1.220.0080.00017.91
8.1.210.0040.00418.77
8.1.200.0040.00717.35
8.1.190.0000.00817.35
8.1.180.0060.00318.10
8.1.170.0030.00518.59
8.1.160.0000.00722.20
8.1.150.0070.00318.68
8.1.140.0030.00617.48
8.1.130.0050.00217.75
8.1.120.0000.00817.56
8.1.110.0040.00417.51
8.1.100.0040.00417.52
8.1.90.0040.00417.52
8.1.80.0070.00017.53
8.1.70.0030.00317.44
8.1.60.0000.00817.62
8.1.50.0000.00817.49
8.1.40.0050.00317.55
8.1.30.0040.00417.60
8.1.20.0040.00417.70
8.1.10.0080.00017.54
8.1.00.0030.00617.60
8.0.300.0000.00718.77
8.0.290.0000.00716.88
8.0.280.0030.00318.50
8.0.270.0000.00717.33
8.0.260.0030.00316.93
8.0.250.0030.00317.05
8.0.240.0040.00417.06
8.0.230.0040.00417.02
8.0.220.0050.00316.88
8.0.210.0000.00716.99
8.0.200.0000.00716.93
8.0.190.0000.01117.03
8.0.180.0050.00216.96
8.0.170.0040.00416.91
8.0.160.0040.00417.04
8.0.150.0000.00716.93
8.0.140.0040.00417.00
8.0.130.0070.00013.48
8.0.120.0040.00416.86
8.0.110.0040.00416.96
8.0.100.0030.00517.11
8.0.90.0070.00016.87
8.0.80.0150.00616.95
8.0.70.0000.00816.91
8.0.60.0000.00816.81
8.0.50.0000.00717.04
8.0.30.0080.01117.07
8.0.20.0090.01017.40
8.0.10.0050.00216.95
8.0.00.0120.00916.88
7.4.330.0000.00515.11
7.4.320.0000.00716.83
7.4.300.0050.00316.69
7.4.290.0090.00016.63
7.4.280.0040.00416.84
7.4.270.0030.00316.88
7.4.260.0030.00516.78
7.4.250.0000.00716.82
7.4.240.0040.00416.83
7.4.230.0030.00316.98
7.4.220.0160.00616.88
7.4.210.0090.01016.90
7.4.200.0000.00716.66
7.4.190.0040.00416.96
7.4.160.0160.00016.95
7.4.150.0120.00617.40
7.4.140.0050.01417.86
7.4.130.0080.01116.89
7.4.120.0070.01116.90
7.4.110.0100.00716.84
7.4.100.0110.00716.76
7.4.90.0160.00816.76
7.4.80.0170.00719.39
7.4.70.0050.01416.71
7.4.60.0090.00916.89
7.4.50.0000.00716.83
7.4.40.0080.00422.77
7.4.30.0030.01516.89
7.4.00.0020.01515.03
7.3.330.0050.00013.66
7.3.320.0000.00513.66
7.3.310.0030.00316.78
7.3.300.0040.00416.70
7.3.290.0040.01116.64
7.3.280.0080.01016.67
7.3.270.0060.01417.40
7.3.260.0110.00816.59
7.3.250.0090.01216.65
7.3.240.0040.01516.59
7.3.230.0120.00616.68
7.3.210.0110.00816.95
7.3.200.0130.00419.39
7.3.190.0060.01116.60
7.3.180.0130.00916.70
7.3.170.0070.01516.78
7.3.160.0160.00716.60
7.3.120.0070.01015.02
7.3.110.0030.01414.97
7.3.100.0030.00615.34
7.3.90.0090.00614.88
7.3.80.0000.00914.85
7.3.70.0090.00615.18
7.3.60.0040.01215.03
7.3.50.0040.01114.93
7.3.40.0000.01815.17
7.3.30.0100.00715.05
7.3.20.0000.01216.73
7.3.10.0160.00016.81
7.3.00.0060.00716.87
7.2.330.0100.00717.05
7.2.320.0080.01216.84
7.2.310.0100.01017.07
7.2.300.0030.01816.91
7.2.290.0140.00316.96
7.2.250.0040.01215.13
7.2.240.0070.01115.20
7.2.230.0000.01515.41
7.2.220.0000.01115.50
7.2.210.0040.01115.21
7.2.200.0000.01315.30
7.2.190.0030.01315.49
7.2.180.0070.00715.51
7.2.170.0070.01015.34
7.2.130.0120.00916.87
7.2.120.0040.01117.19
7.2.110.0160.00516.69
7.2.100.0160.00816.85
7.2.90.0090.00916.67
7.2.80.0170.00316.94
7.2.70.0110.00416.79
7.2.60.0060.01216.81
7.2.50.0150.00616.99
7.2.40.0110.00617.14
7.2.30.0200.00317.03
7.2.20.0000.01216.92
7.2.10.0060.00916.75
7.2.00.0060.01017.01
7.1.330.0080.00615.92
7.1.320.0100.00316.15
7.1.310.0000.01416.13
7.1.300.0090.00615.79
7.1.290.0030.00915.80
7.1.280.0060.00615.90
7.1.270.0060.00616.05
7.1.260.0070.01015.84
7.1.250.0160.00816.02
7.1.200.0080.00416.01
7.1.70.0040.00417.39
7.1.60.0070.01019.82
7.1.50.0060.01617.29
7.1.00.0000.03722.41
7.0.200.0030.00616.80
7.0.140.0070.07322.23
7.0.60.0170.05720.09
7.0.50.0130.07717.95
7.0.40.0070.05020.12
7.0.30.0270.06720.35
7.0.20.0270.07720.04
7.0.10.0070.06720.08
7.0.00.0070.08720.34
5.6.280.0130.06720.85
5.6.210.0230.07020.53
5.6.200.0070.08018.18
5.6.190.0030.09020.60
5.6.180.0530.07320.49
5.6.170.0270.04720.56
5.6.160.0130.07320.44
5.6.150.0000.04318.18
5.6.140.0170.06718.18
5.6.130.0030.09018.25
5.6.120.0170.03721.05
5.6.110.0030.08021.01
5.6.100.0130.07721.07
5.6.90.0070.05321.13
5.6.80.0170.07020.46
5.5.350.0130.04320.39
5.5.340.0000.04317.97
5.5.330.0100.08320.41
5.5.320.0270.07720.24
5.5.310.0370.07020.32
5.5.300.0130.07318.00
5.5.290.0070.06717.98
5.5.280.0030.04020.83
5.5.270.0100.08020.85
5.5.260.0170.07320.86
5.5.250.0070.08020.68
5.5.240.0100.07320.36
5.4.450.0230.07719.36
5.4.440.0770.05319.30
5.4.430.0730.05719.37
5.4.420.0800.05719.27
5.4.410.0800.07019.18
5.4.400.1100.07018.56
5.4.390.1000.05018.79
5.4.380.0270.05718.84
5.4.370.0170.05018.53
5.4.360.0230.04318.61
5.4.350.0130.05718.75
5.4.340.0270.04018.61
5.4.320.0070.03512.53
5.4.310.0070.05412.53
5.4.300.0060.03912.54
5.4.290.0070.03712.53
5.4.280.0090.03212.43
5.4.270.0070.03812.43
5.4.260.0060.03912.43
5.4.250.0040.04212.43
5.4.240.0050.03812.43
5.4.230.0070.04812.42
5.4.220.0110.04912.43
5.4.210.0060.04612.42
5.4.200.0070.03912.42
5.4.190.0000.05718.75
5.4.180.0070.05019.09
5.4.170.0170.05018.79
5.4.160.0100.04718.98
5.4.150.0070.05319.01
5.4.140.0100.04716.61
5.4.130.0070.07316.60
5.4.120.0070.05316.59
5.4.110.0030.05316.53
5.4.100.0130.06316.71
5.4.90.0170.03716.68
5.4.80.0070.04716.45
5.4.70.0100.04716.45
5.4.60.0100.04716.36
5.4.50.0130.06716.42
5.4.40.0130.04316.55
5.4.30.0230.03716.46
5.4.20.0200.05016.64
5.4.10.0070.05316.53
5.4.00.0170.06016.07
5.3.290.0060.04012.80
5.3.280.0060.03912.71
5.3.270.0000.07314.78
5.3.260.0030.05314.81
5.3.250.0030.05314.73
5.3.240.0070.05314.63
5.3.230.0070.05314.72
5.3.220.0030.05714.43
5.3.210.0130.05014.78
5.3.200.0070.05314.82
5.3.190.0100.05014.79
5.3.180.0100.05014.60
5.3.170.0030.07314.76
5.3.160.0030.05314.57
5.3.150.0100.05014.59
5.3.140.0100.06014.65
5.3.130.0030.05314.75
5.3.120.0030.05314.66
5.3.110.0030.05314.66
5.3.100.0070.05014.23
5.3.90.0070.04714.13
5.3.80.0230.03314.04
5.3.70.0130.04314.04
5.3.60.0100.05014.05
5.3.50.0130.04713.83
5.3.40.0000.05314.06
5.3.30.0030.05714.04
5.3.20.0100.04313.82
5.3.10.0070.05313.77
5.3.00.0070.05013.84
5.2.170.0000.04311.25
5.2.160.0030.04011.37
5.2.150.0070.04011.14
5.2.140.0070.04311.40
5.2.130.0100.03711.21
5.2.120.0030.04011.37
5.2.110.0100.04011.23
5.2.100.0000.04311.23
5.2.90.0070.04011.37
5.2.80.0000.06311.22
5.2.70.0070.04311.20
5.2.60.0100.04011.08
5.2.50.0100.03711.25
5.2.40.0100.05011.00
5.2.30.0030.04310.92
5.2.20.0100.03711.01
5.2.10.0170.03710.90
5.2.00.0000.04710.93
5.1.60.0070.03710.00
5.1.50.0070.03710.02
5.1.40.0070.03010.17
5.1.30.0030.04310.54
5.1.20.0030.04010.35
5.1.10.0070.03310.20
5.1.00.0000.04010.03
5.0.50.0030.0278.61
5.0.40.0030.0278.39
5.0.30.0030.0508.20
5.0.20.0030.0278.11
5.0.10.0030.0278.23
5.0.00.0070.0378.20
4.4.90.0070.0177.34
4.4.80.0030.0277.34
4.4.70.0070.0177.34
4.4.60.0000.0277.34
4.4.50.0000.0237.34
4.4.40.0070.0437.34
4.4.30.0000.0237.34
4.4.20.0000.0307.34
4.4.10.0000.0277.34
4.4.00.0030.0337.34
4.3.110.0000.0307.34
4.3.100.0000.0237.34
4.3.90.0030.0207.34
4.3.80.0130.0237.34
4.3.70.0100.0107.34
4.3.60.0030.0207.34
4.3.50.0030.0207.34
4.3.40.0070.0277.34
4.3.30.0000.0277.34
4.3.20.0030.0207.34
4.3.10.0000.0237.34
4.3.00.0000.0237.63

preferences:
50.09 ms | 401 KiB | 5 Q