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['email']は未定義) $_POST['name'] = array( // 異常な値(本来は文字列で来るはず) 'INVALID' => 'これは無効な値です', ); $_POST['age'] = ' 20 '; // 正常な値(半角スペースが混入) $_POST['gender'] = ' male     '; // 正常な値(半角スペースと全角スペースが混入) $_POST['comment'] = ' はじめまして!!    '; // 正常な値 $_POST['options'] = array( 'a' => 'yes', // 正常な値 'b' => "\x0a\x0a\xff", // 値のエンコーディングが壊れている 'c' => array('INVALID' => 'これは無効な値です'), // 異常な値(本来は文字列で来るはず) "\x0a\x0a\xff" => 'INVALID', // キーのエンコーディングが壊れている ); // $_POSTの要素を期待する形になるようにシンボルテーブルにインポートする extract(filter_struct_utf8(INPUT_POST, array( 'name' => '', // 異常なときは強制的に空文字列にする 'age' => FILTER_STRUCT_FULL_TRIM, // 全角スペースなども含むトリミングを行う 'email' => '', // 異常なときは強制的に空文字列にする 'gender' => FILTER_STRUCT_TRIM, // トリミングを行う 'comment' => '', // 異常なときは強制的に空文字列にする // 強制的に一次元配列にし、各要素に対して全角スペースなども含むトリミングを行う 'options' => FILTER_STRUCT_FORCE_ARRAY | FILTER_STRUCT_FULL_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.0120.00318.80
8.3.50.0100.01221.27
8.3.40.0110.00418.92
8.3.30.0110.00420.42
8.3.20.0040.00420.53
8.3.10.0080.00021.05
8.3.00.0000.00823.61
8.2.180.0090.00616.88
8.2.170.0110.00722.96
8.2.160.0100.00320.35
8.2.150.0050.00324.18
8.2.140.0030.00524.66
8.2.130.0070.00026.16
8.2.120.0060.00319.57
8.2.110.0060.00319.18
8.2.100.0040.00817.84
8.2.90.0050.00319.25
8.2.80.0040.00418.05
8.2.70.0030.00717.50
8.2.60.0060.00318.03
8.2.50.0060.00318.07
8.2.40.0000.00918.34
8.2.30.0080.00019.55
8.2.20.0040.00417.96
8.2.10.0040.00417.94
8.2.00.0040.00417.97
8.1.280.0100.01025.92
8.1.270.0040.00423.99
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0090.00023.96
8.1.230.0110.00020.99
8.1.220.0030.00618.77
8.1.210.0050.00319.07
8.1.200.0030.00617.35
8.1.190.0000.00817.53
8.1.180.0040.00418.10
8.1.170.0030.00518.71
8.1.160.0000.00818.86
8.1.150.0080.00018.80
8.1.140.0040.00417.51
8.1.130.0040.00417.88
8.1.120.0040.00417.49
8.1.110.0000.00817.35
8.1.100.0000.00817.57
8.1.90.0050.00217.47
8.1.80.0040.00417.51
8.1.70.0040.00417.43
8.1.60.0030.00817.64
8.1.50.0000.00717.59
8.1.40.0060.00317.53
8.1.30.0040.00417.59
8.1.20.0060.00317.70
8.1.10.0030.00617.63
8.1.00.0000.00817.57
8.0.300.0040.00420.20
8.0.290.0040.00417.30
8.0.280.0040.00418.49
8.0.270.0000.00717.18
8.0.260.0000.00716.84
8.0.250.0040.00417.08
8.0.240.0060.00316.96
8.0.230.0040.00417.07
8.0.220.0060.00316.96
8.0.210.0000.00716.91
8.0.200.0040.00417.01
8.0.190.0000.00716.94
8.0.180.0030.00617.01
8.0.170.0000.00816.85
8.0.160.0040.00316.98
8.0.150.0040.00416.98
8.0.140.0040.00416.97
8.0.130.0030.00313.43
8.0.120.0050.00316.94
8.0.110.0040.00416.96
8.0.100.0030.00516.96
8.0.90.0050.00217.02
8.0.80.0060.01016.98
8.0.70.0000.00816.84
8.0.60.0030.00517.12
8.0.50.0080.00017.12
8.0.30.0150.01117.13
8.0.20.0060.01317.40
8.0.10.0000.00717.06
8.0.00.0090.01017.07
7.4.330.0020.00316.70
7.4.320.0030.00316.89
7.4.300.0030.00316.79
7.4.290.0050.00316.88
7.4.280.0000.00716.79
7.4.270.0040.00316.88
7.4.260.0000.00513.54
7.4.250.0090.00016.63
7.4.240.0040.00416.70
7.4.230.0000.00716.52
7.4.220.0060.01216.79
7.4.210.0070.01016.90
7.4.200.0070.00017.04
7.4.190.0000.00717.00
7.4.160.0130.00616.83
7.4.150.0150.00717.40
7.4.140.0110.00817.86
7.4.130.0100.00816.70
7.4.120.0130.00916.90
7.4.110.0090.00916.89
7.4.100.0120.00616.61
7.4.90.0150.00416.84
7.4.80.0060.01219.39
7.4.70.0100.01316.68
7.4.60.0070.01016.77
7.4.50.0030.00616.78
7.4.40.0100.00622.77
7.4.30.0030.01416.86
7.4.00.0060.01015.09
7.3.330.0030.00313.70
7.3.320.0030.00313.69
7.3.310.0040.00416.48
7.3.300.0030.00316.60
7.3.290.0060.00916.63
7.3.280.0080.00916.59
7.3.270.0060.01317.40
7.3.260.0110.00818.24
7.3.250.0130.00816.61
7.3.240.0090.00916.65
7.3.230.0100.00716.61
7.3.210.0130.00616.61
7.3.200.0150.00919.39
7.3.190.0100.00716.91
7.3.180.0080.00816.44
7.3.170.0060.01016.55
7.3.160.0100.00716.67
7.3.120.0080.00915.00
7.3.110.0110.00614.98
7.3.100.0060.01015.09
7.3.90.0070.00315.28
7.3.80.0070.00715.02
7.3.70.0060.00914.91
7.3.60.0040.00814.87
7.3.50.0060.00615.07
7.3.40.0100.00315.01
7.3.30.0030.01015.08
7.3.20.0080.00417.00
7.3.10.0050.00517.03
7.3.00.0080.00316.83
7.2.330.0180.00316.99
7.2.320.0070.01416.83
7.2.310.0110.00617.02
7.2.300.0060.01216.92
7.2.290.0100.00717.04
7.2.250.0200.00015.22
7.2.240.0130.00715.45
7.2.230.0060.01015.32
7.2.220.0110.00615.39
7.2.210.0060.00615.41
7.2.200.0030.01315.18
7.2.190.0060.00915.33
7.2.180.0090.00615.51
7.2.170.0070.00715.34
7.2.60.0060.01017.21
7.2.00.0070.00719.73
7.1.330.0000.01616.05
7.1.320.0120.00315.95
7.1.310.0040.00815.77
7.1.300.0090.00415.97
7.1.290.0100.00315.89
7.1.280.0060.00615.85
7.1.270.0070.00715.92
7.1.260.0000.01016.12
7.1.200.0040.01115.76
7.1.100.0070.00718.31
7.1.70.0000.00917.41
7.1.60.0070.01419.17
7.1.50.0220.01935.18
7.1.00.0030.06322.29
7.0.200.0040.00717.14
7.0.140.0030.07322.07
7.0.100.0000.04720.00
7.0.90.0100.03720.11
7.0.80.0170.04320.01
7.0.70.0030.03319.96
7.0.60.0130.05019.96
7.0.50.0070.03320.41
7.0.40.0070.04020.01
7.0.30.0030.04320.04
7.0.20.0130.02720.04
7.0.10.0030.04020.04
7.0.00.0070.03720.07
5.6.280.0030.07720.93
5.6.250.0000.03720.55
5.6.240.0030.04020.71
5.6.230.0000.04720.62
5.6.220.0030.04320.55
5.6.210.0170.03020.68
5.6.200.0100.03721.06
5.6.190.0000.04021.14
5.6.180.0070.03721.16
5.6.170.0070.03720.99
5.6.160.0000.04721.07
5.6.150.0000.04021.10
5.6.140.0000.07721.06
5.6.130.0100.07021.07
5.6.120.0030.07721.04
5.6.110.0000.05321.13
5.6.100.0030.08721.03
5.6.90.0070.08021.12
5.6.80.0070.04320.45
5.6.70.0070.05320.45
5.6.60.0030.09020.41
5.6.50.0170.06020.42
5.6.40.0070.06720.43
5.6.30.0070.08020.35
5.6.20.0100.07720.38
5.6.10.0200.07020.41
5.6.00.0000.07320.45
5.5.380.0030.04320.41
5.5.370.0030.04020.57
5.5.360.0030.04020.36
5.5.350.0030.04720.35
5.5.340.0030.04020.79
5.5.330.0100.02720.91
5.5.320.0070.03720.89
5.5.310.0000.04320.88
5.5.300.0130.07720.82
5.5.290.0030.07320.79
5.5.280.0030.04320.85
5.5.270.0030.04720.92
5.5.260.0100.08720.75
5.5.250.0100.08320.77
5.5.240.0030.05020.29
5.5.230.0170.06720.23
5.5.220.0070.08720.32
5.5.210.0170.04020.21
5.5.200.0170.06720.18
5.5.190.0100.07320.15
5.5.180.0000.08020.20
5.5.160.0130.07020.21
5.5.150.0270.05720.25
5.5.140.0130.07020.02
5.5.130.0130.07320.02
5.5.120.0070.08020.26
5.5.110.0070.08320.01
5.5.100.0070.06320.10
5.5.90.0070.07720.07
5.5.80.0070.08320.07
5.5.70.0130.07020.09
5.5.60.0130.06720.06
5.5.50.0100.07719.96
5.5.40.0070.07320.08
5.5.30.0100.06020.14
5.5.20.0030.08020.08
5.5.10.0130.07020.07
5.5.00.0070.07720.16
5.4.450.0130.07719.45
5.4.440.0100.03319.17
5.4.430.0030.04019.17
5.4.420.0070.07319.36
5.4.410.0000.08019.09
5.4.400.0000.08319.19
5.4.390.0100.05319.14
5.4.380.0030.04319.14
5.4.370.0100.07019.15
5.4.360.0030.05719.05
5.4.350.0070.07019.12
5.4.340.0100.07319.23
5.4.320.0130.07018.90
5.4.310.0130.07019.09
5.4.300.0100.07318.88
5.4.290.0070.07019.05
5.4.280.0030.05719.14
5.4.270.0130.06019.04
5.4.260.0000.07318.91
5.4.250.0100.06718.88
5.4.240.0030.07019.18
5.4.230.0130.06319.13
5.4.220.0070.07719.03
5.4.210.0300.02719.02
5.4.200.0100.07019.17
5.4.190.0230.05719.12
5.4.180.0200.04719.15
5.4.170.0070.04319.02
5.4.160.0070.06718.88
5.4.150.0100.07719.05
5.4.140.0170.07316.42
5.4.130.0030.08016.48
5.4.120.0070.03716.51
5.4.110.0000.07316.56
5.4.100.0100.06716.56
5.4.90.0070.04316.55
5.4.80.0100.07316.55
5.4.70.0200.05716.43
5.4.60.0030.07716.40
5.4.50.0100.02716.46
5.4.40.0070.03016.46
5.4.30.0030.07716.36
5.4.20.0100.06316.32
5.4.10.0070.07716.39
5.4.00.0030.05315.79
5.3.290.0100.05014.79
5.3.280.0100.06714.60
5.3.270.0070.07014.60
5.3.260.0030.04714.75
5.3.250.0030.07014.75
5.3.240.0000.07714.75
5.3.230.0070.07314.55
5.3.220.0030.05014.59
5.3.210.0130.03314.58
5.3.200.0000.06014.71
5.3.190.0100.07314.69
5.3.180.0030.05014.74
5.3.170.0030.07014.74
5.3.160.0000.04714.52
5.3.150.0100.07014.66
5.3.140.0100.07314.61
5.3.130.0000.09314.64
5.3.120.0130.06714.50
5.3.110.0000.06014.65
5.3.100.0070.07714.10
5.3.90.0000.08014.19
5.3.80.0100.06014.07
5.3.70.0100.06713.98
5.3.60.0000.08314.06
5.3.50.0030.06714.02
5.3.40.0230.05013.91
5.3.30.0100.07313.93
5.3.20.0070.07313.85
5.3.10.0000.04013.72
5.3.00.0100.05013.60
5.2.170.0030.06712.25
5.2.160.0100.05712.25
5.2.150.0170.04312.25
5.2.140.0130.02712.25
5.2.130.0030.05712.25
5.2.120.0070.03012.25
5.2.110.0030.06012.25
5.2.100.0100.05712.25
5.2.90.0070.03312.25
5.2.80.0070.06012.25
5.2.70.0070.05712.25
5.2.60.0070.04712.25
5.2.50.0030.04312.25
5.2.40.0030.03312.25
5.2.30.0030.06012.25
5.2.20.0100.05712.25
5.2.10.0030.05712.25
5.2.00.0000.06312.25
5.1.60.0030.04312.25
5.1.50.0030.03312.25
5.1.40.0030.04712.25
5.1.30.0070.05012.25
5.1.20.0000.06312.25
5.1.10.0030.04712.25
5.1.00.0100.03312.25
5.0.50.0000.04312.25
5.0.40.0000.02312.25
5.0.30.0030.07012.25
5.0.20.0000.02312.25
5.0.10.0000.02012.25
5.0.00.0070.04712.25
4.4.90.0000.03712.25
4.4.80.0030.03012.25
4.4.70.0070.03312.25
4.4.60.0000.04312.25
4.4.50.0000.03012.25
4.4.40.0100.03712.25
4.4.30.0000.03312.25
4.4.20.0000.03712.25
4.4.10.0000.02012.25
4.4.00.0070.03712.25
4.3.110.0000.02712.25
4.3.100.0000.02312.25
4.3.90.0000.01712.25
4.3.80.0030.04312.25
4.3.70.0070.02312.25
4.3.60.0070.03012.25
4.3.50.0000.02312.25
4.3.40.0030.04012.25
4.3.30.0000.02312.25
4.3.20.0000.03312.25
4.3.10.0000.03012.25
4.3.00.0000.02312.25

preferences:
54.01 ms | 401 KiB | 5 Q