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.0070.00716.75
8.3.50.0090.01022.00
8.3.40.0070.00718.86
8.3.30.0110.00418.99
8.3.20.0040.00420.29
8.3.10.0000.00823.61
8.3.00.0090.00019.50
8.2.180.0160.00616.75
8.2.170.0090.00622.96
8.2.160.0080.00620.16
8.2.150.0030.00624.18
8.2.140.0080.00024.66
8.2.130.0000.00826.16
8.2.120.0040.00422.25
8.2.110.0030.00622.25
8.2.100.0040.01517.68
8.2.90.0040.00417.97
8.2.80.0060.00319.23
8.2.70.0080.00018.04
8.2.60.0040.00418.04
8.2.50.0030.00518.10
8.2.40.0040.00420.64
8.2.30.0070.00018.12
8.2.20.0040.00417.95
8.2.10.0040.00418.03
8.2.00.0030.00617.98
8.1.280.0070.01425.92
8.1.270.0080.00022.20
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0090.00022.19
8.1.230.0040.00720.88
8.1.220.0050.00317.80
8.1.210.0000.01018.77
8.1.200.0050.00317.35
8.1.190.0030.00517.23
8.1.180.0080.00018.10
8.1.170.0070.00318.46
8.1.160.0000.00822.25
8.1.150.0040.00418.72
8.1.140.0000.00817.55
8.1.130.0030.00517.75
8.1.120.0070.00017.42
8.1.110.0040.00417.50
8.1.100.0000.00717.39
8.1.90.0000.00817.49
8.1.80.0060.00317.46
8.1.70.0030.00317.49
8.1.60.0000.00917.58
8.1.50.0030.00617.50
8.1.40.0030.00617.60
8.1.30.0080.00017.56
8.1.20.0000.00817.77
8.1.10.0030.00517.51
8.1.00.0050.00217.56
8.0.300.0000.00720.08
8.0.290.0050.00216.88
8.0.280.0000.00718.37
8.0.270.0050.00217.32
8.0.260.0000.00716.98
8.0.250.0030.00616.97
8.0.240.0000.00717.03
8.0.230.0070.00017.11
8.0.220.0000.00716.90
8.0.210.0070.00017.03
8.0.200.0030.00317.10
8.0.190.0040.00417.11
8.0.180.0090.00317.05
8.0.170.0080.00017.08
8.0.160.0040.00416.95
8.0.150.0000.00917.02
8.0.140.0000.00916.96
8.0.130.0000.00713.45
8.0.120.0030.00616.88
8.0.110.0050.00216.91
8.0.100.0040.00416.91
8.0.90.0040.00416.86
8.0.80.0090.00916.93
8.0.70.0040.00416.83
8.0.60.0080.00016.88
8.0.50.0040.00417.02
8.0.30.0090.01117.21
8.0.20.0140.00617.43
8.0.10.0030.00617.07
8.0.00.0140.01516.88
7.4.330.0000.00515.00
7.4.320.0060.00016.63
7.4.300.0060.00016.86
7.4.290.0030.00516.87
7.4.280.0030.00616.76
7.4.270.0030.00316.80
7.4.260.0030.00616.74
7.4.250.0000.00716.82
7.4.240.0060.00116.87
7.4.230.0030.00316.97
7.4.220.0130.00716.76
7.4.210.0060.01116.95
7.4.200.0070.00016.92
7.4.190.0000.00816.73
7.4.160.0190.00416.76
7.4.150.0110.00717.40
7.4.140.0120.01017.86
7.4.130.0090.00816.74
7.4.120.0140.00816.78
7.4.110.0160.00316.63
7.4.100.0120.00816.76
7.4.90.0170.00316.68
7.4.80.0120.00819.39
7.4.70.0120.00616.68
7.4.60.0090.00616.91
7.4.50.0040.00716.83
7.4.40.0070.01122.77
7.4.30.0080.00916.50
7.4.00.0030.01515.30
7.3.330.0030.00313.55
7.3.320.0000.00913.69
7.3.310.0000.00716.59
7.3.300.0050.00316.56
7.3.290.0130.00316.59
7.3.280.0120.00616.68
7.3.270.0130.00517.40
7.3.260.0040.01516.61
7.3.250.0080.01316.59
7.3.240.0110.01116.58
7.3.230.0100.00716.62
7.3.210.0130.00316.57
7.3.200.0110.00819.39
7.3.190.0130.00616.75
7.3.180.0030.01316.83
7.3.170.0100.00616.88
7.3.160.0130.00316.80
7.3.120.0110.00415.08
7.3.10.0130.00617.05
7.3.00.0070.01116.69
7.2.330.0110.00716.95
7.2.320.0120.01316.94
7.2.310.0110.01116.79
7.2.300.0100.00716.95
7.2.290.0110.00716.75
7.2.130.0100.01717.21
7.2.120.0100.00017.17
7.2.110.0040.00817.12
7.2.100.0060.01017.16
7.2.90.0030.01217.15
7.2.80.0030.00917.06
7.2.70.0120.00316.99
7.2.60.0090.00617.24
7.2.50.0030.00716.88
7.2.40.0100.00717.14
7.2.30.0090.00617.21
7.2.20.0070.00717.14
7.2.10.0090.00617.25
7.2.00.0050.00818.37
7.1.250.0110.00716.13
7.1.100.0000.01218.04
7.1.70.0030.00617.39
7.1.60.0200.00719.33
7.1.50.0140.02035.11
7.1.00.0130.07022.46
7.0.200.0000.00716.98
7.0.140.0100.06722.14
7.0.60.0270.06020.09
7.0.50.0070.05318.00
7.0.40.0000.04720.26
7.0.30.0300.08320.11
7.0.20.0330.07720.11
7.0.10.0030.04720.21
7.0.00.0100.07320.22
5.6.280.0030.07321.11
5.6.210.0130.06720.53
5.6.200.0070.03718.16
5.6.190.0170.05320.58
5.6.180.0170.05020.52
5.6.170.0300.05720.48
5.6.160.0100.06020.57
5.6.150.0100.08018.19
5.6.140.0030.09018.28
5.6.130.0100.08018.27
5.6.120.0230.07021.07
5.6.110.0170.07321.02
5.6.100.0130.07021.16
5.6.90.0130.06321.01
5.6.80.0100.07720.55
5.6.70.4500.04020.41
5.5.350.0100.03320.30
5.5.340.0100.07317.99
5.5.330.0030.07720.21
5.5.320.0230.05320.27
5.5.310.0130.04720.32
5.5.300.0070.05717.94
5.5.290.0100.07018.07
5.5.280.0200.08020.93
5.5.270.0100.05720.89
5.5.260.0100.09020.78
5.5.250.0100.06020.64
5.5.240.0070.05320.39
5.4.450.1130.03019.49
5.4.440.0970.06019.34
5.4.430.1070.05319.47
5.4.420.1000.05019.19
5.4.410.1070.05019.41
5.4.400.0430.07319.16
5.4.390.0500.05319.15
5.4.380.0170.06318.82
5.4.370.0170.05318.77
5.4.360.0400.04318.61
5.4.350.0270.04718.74
5.4.340.0230.06018.61
5.4.320.0080.04212.54
5.4.310.0020.04112.53
5.4.300.0100.03912.54
5.4.290.0060.03612.53
5.4.280.0090.03512.43
5.4.270.0070.04312.43
5.4.260.0050.04012.43
5.4.250.0030.04012.43
5.4.240.0030.04512.43
5.4.230.0050.03812.42
5.4.220.0020.04212.42
5.4.210.0090.03212.43
5.4.200.0040.05012.43
5.4.190.0170.04012.41
5.4.180.0140.05012.41
5.4.170.0150.04812.42
5.4.160.0170.04212.41
5.4.150.0120.04912.41
5.4.140.0150.04412.09
5.4.130.0140.04612.09
5.4.120.0170.04212.04
5.4.110.0160.04412.04
5.4.100.0160.04212.03
5.4.90.0150.04312.04
5.4.80.0160.04512.04
5.4.70.0150.04312.04
5.4.60.0140.04312.04
5.4.50.0180.03912.03
5.4.40.0110.04612.02
5.4.30.0120.04612.02
5.4.20.0160.04012.02
5.4.10.0170.04012.02
5.4.00.0280.09011.50
5.3.290.0070.04112.80
5.3.280.0050.03912.73
5.3.270.0180.04312.72
5.3.260.0180.04412.72
5.3.250.0220.03912.72
5.3.240.0170.04712.71
5.3.230.0130.04912.71
5.3.220.0180.04312.68
5.3.210.0190.04312.68
5.3.200.0170.04212.68
5.3.190.0150.04612.68
5.3.180.0140.04612.68
5.3.170.0170.04312.68
5.3.160.0240.06512.67
5.3.150.0150.04412.67
5.3.140.0150.04512.66
5.3.130.0370.08812.66
5.3.120.0200.04112.66
5.3.110.0200.04112.66
5.3.100.0110.04812.15
5.3.90.0360.08212.13
5.3.80.0150.04512.12
5.3.70.0130.04612.12
5.3.60.0170.04212.10
5.3.50.0200.04012.05
5.3.40.0160.04712.05
5.3.30.0190.03912.01
5.3.20.0170.04511.79
5.3.10.0200.03811.76
5.3.00.0130.04711.74
5.2.170.0340.0789.25
5.2.160.0350.0749.25
5.2.150.0130.0349.25
5.2.140.0130.0369.25
5.2.130.0220.0579.21
5.2.120.0110.0379.21
5.2.110.0130.0389.21
5.2.100.0150.0369.21
5.2.90.0200.0579.21
5.2.80.0090.0379.20
5.2.70.0070.0409.20
5.2.60.0140.0329.17
5.2.50.0120.0349.13
5.2.40.0130.0339.13
5.2.30.0130.0339.09
5.2.20.0090.0389.09
5.2.10.0340.0728.98
5.2.00.0110.0348.84
5.1.60.0060.0338.12
5.1.50.0100.0308.11
5.1.40.0110.0298.10
5.1.30.0110.0318.45
5.1.20.0120.0308.48
5.1.10.0100.0328.19
5.1.00.0080.0328.19
5.0.50.0100.0236.63
5.0.40.0080.0246.48
5.0.30.0140.0606.30
5.0.20.0100.0216.26
5.0.10.0100.0206.23
5.0.00.0100.0346.23
4.4.90.0050.0194.78
4.4.80.0090.0154.75
4.4.70.0080.0174.75
4.4.60.0050.0204.76
4.4.50.0080.0164.77
4.4.40.0050.0304.71
4.4.30.0150.0414.76
4.4.20.0050.0204.85
4.4.10.0080.0174.85
4.4.00.0100.0554.76
4.3.110.0060.0184.67
4.3.100.0050.0194.66
4.3.90.0060.0184.63
4.3.80.0040.0304.58
4.3.70.0100.0144.63
4.3.60.0070.0164.63
4.3.50.0090.0154.63
4.3.40.0050.0284.54
4.3.30.0050.0193.30
4.3.20.0050.0183.28
4.3.10.0040.0183.24
4.3.00.0030.01715.61

preferences:
54.9 ms | 401 KiB | 5 Q