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\xff This is invalid encoding value", "\x0a\x0a\xff" => '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.0220.00018.68
8.3.50.0170.00422.05
8.3.40.0110.00418.92
8.3.30.0090.00618.82
8.3.20.0050.00318.90
8.3.10.0030.00521.24
8.3.00.0080.00023.66
8.2.180.0120.00617.00
8.2.170.0040.01122.96
8.2.160.0060.00920.39
8.2.150.0000.00824.18
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0050.00320.98
8.2.110.0070.00320.35
8.2.100.0090.00317.84
8.2.90.0040.00419.17
8.2.80.0080.00017.97
8.2.70.0060.00317.75
8.2.60.0000.00817.93
8.2.50.0120.00018.07
8.2.40.0040.00418.09
8.2.30.0000.00921.13
8.2.20.0030.00617.96
8.2.10.0040.00418.04
8.2.00.0040.00417.80
8.1.280.0180.00325.92
8.1.270.0050.00323.99
8.1.260.0080.00826.35
8.1.250.0040.00428.09
8.1.240.0100.00022.55
8.1.230.0040.00720.95
8.1.220.0040.00418.77
8.1.210.0040.00418.85
8.1.200.0060.00317.35
8.1.190.0040.00417.53
8.1.180.0040.00418.10
8.1.170.0060.00318.56
8.1.160.0000.00718.94
8.1.150.0000.00818.65
8.1.140.0080.00017.50
8.1.130.0070.00017.80
8.1.120.0040.00417.57
8.1.110.0040.00417.51
8.1.100.0000.00817.42
8.1.90.0000.00717.47
8.1.80.0050.00317.41
8.1.70.0070.00017.49
8.1.60.0000.00917.52
8.1.50.0040.00417.57
8.1.40.0070.00017.52
8.1.30.0040.00417.64
8.1.20.0050.00317.77
8.1.10.0060.00317.58
8.1.00.0040.00717.45
8.0.300.0040.00420.10
8.0.290.0040.00417.28
8.0.280.0000.00818.37
8.0.270.0000.00717.30
8.0.260.0000.00716.98
8.0.250.0030.00517.09
8.0.240.0040.00417.04
8.0.230.0000.00716.95
8.0.220.0040.00717.02
8.0.210.0000.00817.00
8.0.200.0020.00516.96
8.0.190.0030.00517.06
8.0.180.0050.00317.11
8.0.170.0000.00717.04
8.0.160.0040.00416.86
8.0.150.0040.00416.88
8.0.140.0040.00416.85
8.0.130.0020.00513.39
8.0.120.0050.00316.95
8.0.110.0030.00617.04
8.0.100.0040.00416.88
8.0.90.0060.00316.98
8.0.80.0060.00916.98
8.0.70.0000.00817.04
8.0.60.0000.00717.09
8.0.50.0080.00016.88
8.0.30.0070.01117.21
8.0.20.0110.00717.40
8.0.10.0040.00417.00
8.0.00.0080.01116.79
7.4.330.0050.00016.68
7.4.320.0020.00516.91
7.4.300.0030.00316.88
7.4.290.0030.00316.75
7.4.280.0030.00316.89
7.4.270.0000.00916.80
7.4.260.0060.00013.65
7.4.250.0000.00816.69
7.4.240.0000.00916.77
7.4.230.0070.00016.97
7.4.220.0130.01316.77
7.4.210.0090.00616.85
7.4.200.0040.00416.78
7.4.190.0040.00416.74
7.4.160.0070.01016.77
7.4.150.0060.01317.40
7.4.140.0170.00217.86
7.4.130.0080.01116.84
7.4.120.0090.00816.76
7.4.110.0110.00716.94
7.4.100.0020.01817.02
7.4.90.0030.01516.67
7.4.80.0140.00319.39
7.4.70.0070.01016.70
7.4.60.0030.01516.66
7.4.50.0000.00916.89
7.4.40.0070.01022.77
7.4.30.0100.00716.94
7.4.00.0100.00315.09
7.3.330.0000.00613.43
7.3.320.0030.00313.69
7.3.310.0040.00416.50
7.3.300.0000.00716.54
7.3.290.0100.00716.61
7.3.280.0070.00916.63
7.3.270.0040.01617.40
7.3.260.0060.01318.24
7.3.250.0090.00916.63
7.3.240.0060.01616.63
7.3.230.0140.00316.83
7.3.210.0090.00916.55
7.3.200.0190.00319.39
7.3.190.0090.00916.67
7.3.180.0130.00316.51
7.3.170.0100.00716.80
7.3.160.0000.01616.63
7.3.120.0090.00915.07
7.3.10.0040.01016.61
7.3.00.0050.00616.83
7.2.330.0110.00716.95
7.2.320.0130.01016.91
7.2.310.0170.00316.92
7.2.300.0100.01616.75
7.2.290.0120.01316.94
7.2.130.0060.00717.25
7.2.120.0020.01217.02
7.2.110.0060.00717.18
7.2.100.0030.01217.16
7.2.90.0020.01317.26
7.2.80.0030.01016.91
7.2.70.0090.00417.21
7.2.60.0080.00617.03
7.2.50.0090.00717.06
7.2.40.0070.00816.97
7.2.30.0050.01017.04
7.2.20.0050.01117.20
7.2.10.0050.00817.04
7.2.00.0080.00616.85
7.1.250.0050.00715.92
7.1.200.0100.00316.10
7.1.70.0040.00417.30
7.1.60.0000.01417.22
7.1.50.0130.01017.39
7.1.00.0130.06722.42
7.0.200.0140.00717.02
7.0.140.0030.07322.18
7.0.80.0170.07319.98
7.0.70.0100.04720.20
7.0.60.0600.07020.00
7.0.50.0430.05020.43
7.0.40.0100.07720.05
7.0.30.0070.08320.04
7.0.20.0070.08320.19
7.0.10.0130.07320.09
7.0.00.0070.09020.14
5.6.280.0070.06720.91
5.6.230.0100.07720.66
5.6.220.0100.05320.52
5.6.210.0070.07320.59
5.6.200.0130.07721.08
5.6.190.0130.07721.07
5.6.180.0030.04321.14
5.6.170.0100.05021.03
5.6.160.0100.08320.99
5.6.150.0030.09021.09
5.6.140.0070.06721.20
5.6.130.0230.07321.14
5.6.120.0170.07321.06
5.6.110.0100.05321.07
5.6.100.0030.09321.10
5.6.90.0130.07321.01
5.6.80.0130.06320.44
5.6.70.0070.05720.37
5.6.60.0130.07020.48
5.6.50.0070.05320.49
5.6.40.0030.07020.48
5.6.30.0100.03320.41
5.6.20.0130.06720.39
5.6.10.0070.08320.46
5.6.00.0070.04720.54
5.5.370.0100.08320.44
5.5.360.0100.07020.43
5.5.350.0230.06020.47
5.5.340.0030.05720.85
5.5.330.0130.06020.79
5.5.320.0070.05020.82
5.5.310.0170.06720.78
5.5.300.0070.08320.95
5.5.290.0000.07320.82
5.5.280.0070.06720.85
5.5.270.0100.08320.93
5.5.260.0100.07720.90
5.5.250.0070.05320.63
5.5.240.0070.08020.16
5.5.230.0030.05720.30
5.5.220.0100.07720.13
5.5.210.0070.07020.27
5.5.200.0030.08320.21
5.5.190.0170.03320.27
5.5.180.0200.06720.16
5.5.160.0000.05320.17
5.5.150.0030.07020.01
5.5.140.0070.05720.28
5.5.130.0070.04720.29
5.5.120.0070.08020.26
5.5.110.0100.05020.29
5.5.100.0070.06720.00
5.5.90.0130.07020.12
5.5.80.0200.03720.19
5.5.70.0100.07320.12
5.5.60.0000.07320.17
5.5.50.0070.07019.96
5.5.40.0100.06720.08
5.5.30.0030.05020.08
5.5.20.0070.04020.17
5.5.10.0070.05320.04
5.5.00.0000.04320.09
5.4.450.0130.07319.23
5.4.440.0100.07319.36
5.4.430.0100.07719.24
5.4.420.0130.06719.50
5.4.410.0030.07719.10
5.4.400.0070.08018.88
5.4.390.0130.05718.90
5.4.380.0070.07319.05
5.4.370.0070.06718.95
5.4.360.0070.07318.85
5.4.350.0030.04019.12
5.4.340.0070.07719.03
5.4.320.0030.04319.06
5.4.310.0000.04019.16
5.4.300.0000.06319.09
5.4.290.0100.04019.17
5.4.280.0070.08018.95
5.4.270.0070.08319.09
5.4.260.0100.08019.02
5.4.250.0070.04319.08
5.4.240.0030.07719.04
5.4.230.0030.07019.13
5.4.220.0070.08019.20
5.4.210.0070.06719.22
5.4.200.0070.05019.11
5.4.190.0130.02719.02
5.4.180.0030.04319.08
5.4.170.0030.04019.08
5.4.160.0000.04319.07
5.4.150.0030.04319.12
5.4.140.0000.04016.44
5.4.130.0070.03316.33
5.4.120.0030.03716.41
5.4.110.0000.04016.44
5.4.100.0030.03316.48
5.4.90.0030.04016.50
5.4.80.0000.03716.52
5.4.70.0000.03716.55
5.4.60.0100.03016.46
5.4.50.0030.03016.38
5.4.40.0000.03316.35
5.4.30.0070.04716.27
5.4.20.0070.07316.49
5.4.10.0000.04316.36
5.4.00.0130.02315.83
5.3.290.0000.04314.62
5.3.280.0170.06314.56
5.3.270.0000.04714.66
5.3.260.0100.04314.64
5.3.250.0030.03714.76
5.3.240.0100.03014.78
5.3.230.0030.04314.62
5.3.220.0030.04014.59
5.3.210.0030.04314.57
5.3.200.0030.04014.52
5.3.190.0030.03714.63
5.3.180.0100.06314.61
5.3.170.0000.07014.56
5.3.160.0030.04014.57
5.3.150.0100.05014.58
5.3.140.0070.03014.55
5.3.130.0000.07014.72
5.3.120.0030.05314.60
5.3.110.0000.04014.64
5.3.100.0170.06714.09
5.3.90.0070.05014.07
5.3.80.0030.05314.08
5.3.70.0070.03314.05
5.3.60.0100.03014.15
5.3.50.0030.03714.07
5.3.40.0070.03314.09
5.3.30.0030.03713.82
5.3.20.0030.06313.86
5.3.10.0100.04713.79
5.3.00.0000.03713.72
5.2.170.0000.03313.64
5.2.160.0000.03313.64
5.2.150.0030.03013.64
5.2.140.0030.03713.64
5.2.130.0000.03013.64
5.2.120.0030.06713.64
5.2.110.0070.02313.64
5.2.100.0030.02313.64
5.2.90.0000.05013.64
5.2.80.0000.03013.64
5.2.70.0070.02713.64
5.2.60.0070.03313.64
5.2.50.0030.03713.64
5.2.40.0030.02713.64
5.2.30.0030.03013.64
5.2.20.0030.02713.64
5.2.10.0000.03313.64
5.2.00.0030.02313.64
5.1.60.0000.04013.64
5.1.50.0030.02313.64
5.1.40.0000.02713.64
5.1.30.0000.03013.64
5.1.20.0000.02713.64
5.1.10.0030.02713.64
5.1.00.0030.02013.64
5.0.50.0000.02013.64
5.0.40.0100.03713.64
5.0.30.0030.06013.64
5.0.20.0030.04313.64
5.0.10.0030.02313.64
5.0.00.0070.06313.64
4.4.90.0030.01013.64
4.4.80.0000.01713.64
4.4.70.0030.02713.64
4.4.60.0000.01713.64
4.4.50.0000.01713.64
4.4.40.0030.03713.64
4.4.30.0000.02013.64
4.4.20.0000.01713.64
4.4.10.0030.01013.64
4.4.00.0030.02713.64
4.3.110.0000.02713.64
4.3.100.0030.03313.64
4.3.90.0030.03313.64
4.3.80.0030.05013.64
4.3.70.0000.03713.64
4.3.60.0030.03013.64
4.3.50.0070.03013.64
4.3.40.0000.05313.64
4.3.30.0030.03313.64
4.3.20.0000.03313.64
4.3.10.0070.03013.64
4.3.00.0000.03713.64

preferences:
47.58 ms | 400 KiB | 5 Q