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' => '', // トリミングを行う '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.0060.00916.63
8.3.50.0160.00717.63
8.3.40.0040.01118.97
8.3.30.0070.00718.84
8.3.20.0000.00918.62
8.3.10.0000.00820.46
8.3.00.0040.00417.63
8.2.180.0140.00416.75
8.2.170.0090.00622.96
8.2.160.0100.01022.20
8.2.150.0080.00024.18
8.2.140.0000.00824.66
8.2.130.0040.00426.16
8.2.120.0060.00319.82
8.2.110.0080.00321.06
8.2.100.0060.00617.97
8.2.90.0000.01021.13
8.2.80.0000.00818.05
8.2.70.0000.00817.75
8.2.60.0030.00617.93
8.2.50.0000.00818.07
8.2.40.0000.00919.88
8.2.30.0040.00418.27
8.2.20.0080.00017.78
8.2.10.0090.00019.50
8.2.00.0040.00417.94
8.1.280.0120.00825.92
8.1.270.0000.00823.99
8.1.260.0030.00526.35
8.1.250.0050.00328.09
8.1.240.0110.00022.54
8.1.230.0080.00420.88
8.1.220.0040.00417.74
8.1.210.0040.00418.89
8.1.200.0070.00317.47
8.1.190.0030.00517.53
8.1.180.0030.00518.10
8.1.170.0030.00618.87
8.1.160.0040.00418.86
8.1.150.0040.00418.64
8.1.140.0000.00817.49
8.1.130.0030.00317.94
8.1.120.0040.00417.54
8.1.110.0040.00417.39
8.1.100.0000.00817.55
8.1.90.0000.00717.52
8.1.80.0050.00217.41
8.1.70.0000.00817.43
8.1.60.0040.00417.60
8.1.50.0040.00417.39
8.1.40.0040.00417.44
8.1.30.0040.00417.59
8.1.20.0080.00017.70
8.1.10.0040.00417.59
8.1.00.0040.00417.54
8.0.300.0070.00320.08
8.0.290.0040.00417.00
8.0.280.0000.00718.48
8.0.270.0040.00417.32
8.0.260.0000.00816.92
8.0.250.0000.01116.99
8.0.240.0050.00517.02
8.0.230.0070.00017.03
8.0.220.0000.00816.91
8.0.210.0030.00616.97
8.0.200.0060.00017.05
8.0.190.0070.00017.11
8.0.180.0070.00017.05
8.0.170.0000.00917.05
8.0.160.0000.00816.91
8.0.150.0060.00316.84
8.0.140.0030.00616.98
8.0.130.0040.00413.40
8.0.120.0040.00417.00
8.0.110.0040.00416.83
8.0.100.0040.00416.88
8.0.90.0000.00817.07
8.0.80.0110.00616.98
8.0.70.0040.00416.88
8.0.60.0000.00716.95
8.0.50.0000.00717.12
8.0.30.0090.01017.08
8.0.20.0110.01417.24
8.0.10.0000.00717.09
8.0.00.0120.00716.92
7.4.330.0050.00013.18
7.4.320.0030.00316.66
7.4.300.0070.00016.78
7.4.290.0000.00716.88
7.4.280.0000.01016.89
7.4.270.0030.00316.79
7.4.260.0000.00613.50
7.4.250.0060.00316.76
7.4.240.0050.00216.80
7.4.230.0030.00316.89
7.4.220.0040.01316.78
7.4.210.0110.00516.93
7.4.200.0040.00316.73
7.4.190.0070.00016.94
7.4.160.0060.01016.70
7.4.150.0080.01117.01
7.4.140.0090.00916.86
7.4.130.0060.01116.75
7.4.120.0090.00916.79
7.4.110.0120.00616.76
7.4.100.0090.01216.91
7.4.90.0120.00616.73
7.4.80.0060.01516.88
7.4.70.0130.00416.53
7.4.60.0130.00316.75
7.4.50.0060.00316.80
7.4.40.0040.01216.80
7.4.30.0050.01116.59
7.4.00.0070.01015.43
7.3.330.0030.00313.60
7.3.320.0030.00313.43
7.3.310.0030.00316.64
7.3.300.0000.00716.68
7.3.290.0120.00316.63
7.3.280.0050.01216.58
7.3.270.0060.01716.63
7.3.260.0070.01016.63
7.3.250.0120.00816.74
7.3.240.0070.01116.62
7.3.230.0130.00516.56
7.3.210.0070.01016.86
7.3.200.0150.00419.39
7.3.190.0130.00616.70
7.3.180.0100.00616.78
7.3.170.0130.00316.51
7.3.160.0140.00616.59
7.3.120.0090.00615.39
7.3.00.0100.00716.51
7.2.330.0090.00916.78
7.2.320.0030.01417.07
7.2.310.0070.01916.70
7.2.300.0080.00916.85
7.2.290.0140.00417.05
7.2.130.0060.00916.76
7.2.120.0000.01816.95
7.2.110.0120.00316.73
7.2.100.0040.01217.16
7.2.90.0090.00617.05
7.2.80.0000.01617.22
7.2.70.0060.00616.70
7.2.60.0070.01316.88
7.2.50.0070.00716.81
7.2.40.0100.00616.92
7.2.30.0040.01217.00
7.2.20.0060.00917.09
7.2.10.0030.01717.16
7.2.00.0030.01118.18
7.1.250.0040.01215.74
7.1.240.0040.01215.82
7.1.230.0040.00815.93
7.1.220.0160.00015.82
7.1.210.0120.00615.86
7.1.200.0070.01315.83
7.1.190.0070.00715.91
7.1.180.0150.00415.86
7.1.170.0110.00715.97
7.1.160.0040.00815.84
7.1.150.0040.01115.77
7.1.140.0070.00715.90
7.1.130.0090.00915.71
7.1.120.0100.00515.82
7.1.110.0030.01315.92
7.1.100.0050.00817.07
7.1.90.0090.00616.07
7.1.80.0040.01315.77
7.1.70.0050.01016.54
7.1.60.0070.01017.67
7.1.50.0120.00816.42
7.1.40.0110.00415.96
7.1.30.0000.01315.91
7.1.20.0100.00615.95
7.1.10.0070.01315.87
7.1.00.0050.04319.16
7.0.330.0070.00715.54
7.0.320.0000.01315.54
7.0.310.0030.01015.75
7.0.300.0110.00715.56
7.0.290.0090.00615.33
7.0.280.0060.00915.63
7.0.270.0100.00715.39
7.0.260.0060.00915.16
7.0.250.0070.01115.55
7.0.240.0100.00715.51
7.0.230.0100.00715.50
7.0.220.0120.00315.48
7.0.210.0040.01815.50
7.0.200.0080.00616.32
7.0.190.0060.00915.27
7.0.180.0100.01015.48
7.0.170.0040.01115.54
7.0.160.0030.00815.62
7.0.150.0090.00915.66
7.0.140.0070.03918.85
7.0.130.0090.00315.62
7.0.120.0050.04118.73
7.0.110.0000.01515.52
7.0.100.0150.00015.46
7.0.90.0080.00815.41
7.0.80.0110.00415.55
7.0.70.0100.01015.31
7.0.60.0160.04317.90
7.0.50.0050.04716.83
7.0.40.0060.02616.79
7.0.30.0100.04016.87
7.0.20.0080.02816.94
7.0.10.0050.02916.95
7.0.00.0050.04217.05
5.6.380.0090.00614.53
5.6.370.0030.01014.13
5.6.360.0090.00614.54
5.6.350.0140.00314.35
5.6.340.0040.01114.22
5.6.330.0110.00714.32
5.6.320.0100.00714.32
5.6.310.0040.01214.43
5.6.300.0070.00714.46
5.6.290.0080.00814.58
5.6.280.0100.03517.54
5.6.270.0090.00914.40
5.6.260.0000.01614.27
5.6.250.0070.00714.29
5.6.240.0080.00714.26
5.6.230.0120.00414.27
5.6.220.0070.01014.32
5.6.210.0030.02517.43
5.6.200.0060.02916.37
5.6.190.0050.03517.62
5.6.180.0050.02717.65
5.6.170.0050.04417.57
5.6.160.0070.04517.62
5.6.150.0100.03717.41
5.6.140.0100.02717.31
5.6.130.0050.03617.38
5.6.120.0090.03517.56
5.6.110.0040.02617.44
5.6.100.0050.02717.53
5.6.90.0070.03117.50
5.6.80.0070.02417.08
5.6.70.0060.02117.04
5.6.60.0070.04217.16
5.6.50.0080.04717.09
5.6.40.0100.04216.90
5.6.30.0120.03716.86
5.6.20.0060.04217.05
5.6.10.0030.05217.02
5.6.00.0090.02317.13
5.5.380.0130.00011.23
5.5.370.0080.00811.52
5.5.360.0070.00911.68
5.5.350.0190.03815.98
5.5.340.0140.03914.65
5.5.330.0060.02515.89
5.5.320.0070.04115.97
5.5.310.0140.03015.95
5.5.300.0080.04515.89
5.5.290.0070.02815.82
5.5.280.0080.03515.80
5.5.270.0050.03715.84
5.5.260.0040.02615.70
5.5.250.0100.04115.53
5.5.240.0010.02915.35
5.5.230.0050.02915.41
5.5.220.0040.04815.36
5.5.210.0100.04415.51
5.5.200.0050.04015.33
5.5.190.0050.04515.46
5.5.180.0060.04215.30
5.5.170.0060.01011.18
5.5.160.0090.02615.35
5.5.150.0070.03215.54
5.5.140.0030.04715.37
5.5.130.0110.01915.37
5.5.120.0100.04215.24
5.5.110.0120.03915.32
5.5.100.0040.02715.29
5.5.90.0020.03215.41
5.5.80.0080.02615.25
5.5.70.0110.03015.20
5.5.60.0080.04515.31
5.5.50.0060.03115.31
5.5.40.0050.02615.29
5.5.30.0060.02315.32
5.5.20.0030.04715.35
5.5.10.0080.04115.27
5.5.00.0070.04115.34
5.4.450.0020.03115.49
5.4.440.0070.04115.21
5.4.430.0100.02715.29
5.4.420.0030.02715.21
5.4.410.0040.04415.36
5.4.400.0030.03815.23
5.4.390.0060.04215.08
5.4.380.0030.03515.14
5.4.370.0080.02115.10
5.4.360.0030.04215.17
5.4.350.0050.04715.13
5.4.340.0080.02815.02
5.4.330.0030.00811.25
5.4.320.0080.02515.16
5.4.310.0100.03615.05
5.4.300.0040.02315.19
5.4.290.0110.03315.17
5.4.280.0040.04415.21
5.4.270.0030.04215.28
5.4.260.0050.02515.18
5.4.250.0080.02515.17
5.4.240.0080.04015.12
5.4.230.0110.03315.31
5.4.220.0050.02615.16
5.4.210.0070.04115.16
5.4.200.0020.02515.02
5.4.190.0070.02215.12
5.4.180.0030.04015.08
5.4.170.0080.02515.02
5.4.160.0110.03315.00
5.4.150.0050.02715.14
5.4.140.0000.02713.87
5.4.130.0080.03813.74
5.4.120.0030.02313.83
5.4.110.0080.03113.94
5.4.100.0070.02813.87
5.4.90.0070.03713.95
5.4.80.0100.03313.88
5.4.70.0080.03813.84
5.4.60.0070.02913.80
5.4.50.0090.03813.83
5.4.40.0100.01713.78
5.4.30.0030.02813.81
5.4.20.0070.01813.79
5.4.10.0090.03213.79
5.4.00.0080.03813.56
5.3.290.0080.01812.94
5.3.280.0030.03312.90
5.3.270.0070.03812.93
5.3.260.0070.02312.91
5.3.250.0090.04712.93
5.3.240.0020.04312.93
5.3.230.0050.02212.86
5.3.220.0060.04112.90
5.3.210.0080.03712.89
5.3.200.0020.04212.83
5.3.190.0060.04312.92
5.3.180.0060.04312.92
5.3.170.0070.02712.89
5.3.160.0000.02912.90
5.3.150.0070.01812.92
5.3.140.0030.02812.89
5.3.130.0070.03812.90
5.3.120.0050.02212.88
5.3.110.0080.04012.91
5.3.100.0070.03712.64
5.3.90.0080.03512.63
5.3.80.0030.03912.59
5.3.70.0110.02012.57
5.3.60.0050.03712.69
5.3.50.0060.02612.56
5.3.40.0020.04512.55
5.3.30.0050.02712.59
5.3.20.0060.02012.48
5.3.10.0030.04012.43
5.3.00.0060.03812.50
5.2.170.0040.03211.26
5.2.160.0090.02711.23
5.2.150.0020.03511.26
5.2.140.0020.02811.16
5.2.130.0070.01611.23
5.2.120.0110.02711.20
5.2.110.0020.03011.11
5.2.100.0030.02111.23
5.2.90.0040.02111.14
5.2.80.0060.01711.23
5.2.70.0040.03311.14
5.2.60.0050.01711.14
5.2.50.0020.02711.20
5.2.40.0030.02611.11
5.2.30.0000.02411.12
5.2.20.0070.03211.10
5.2.10.0020.02911.04
5.2.00.0040.03110.98
5.1.60.0060.02010.59
5.1.50.0070.02110.59
5.1.40.0040.02510.59
5.1.30.0050.02610.81
5.1.20.0050.02710.80
5.1.10.0030.02710.60
5.1.00.0040.01610.63
5.0.50.0000.0259.85
5.0.40.0010.0259.81
5.0.30.0000.0459.71
5.0.20.0040.0209.77
5.0.10.0050.0209.71
5.0.00.0030.0329.65
4.4.90.0020.0189.27
4.4.80.0020.0139.27
4.4.70.0020.0149.27
4.4.60.0080.0129.27
4.4.50.0000.0179.27
4.4.40.0040.0139.27
4.4.30.0050.0189.27
4.4.20.0030.0189.27
4.4.10.0000.0199.27
4.4.00.0030.0159.27
4.3.110.0030.0189.27
4.3.100.0020.0139.27
4.3.90.0000.0179.27
4.3.80.0020.0249.27
4.3.70.0020.0149.27
4.3.60.0030.0099.27
4.3.50.0020.0109.27
4.3.40.0000.0159.27
4.3.30.0030.0089.27
4.3.20.0000.0119.27
4.3.10.0020.0139.27
4.3.00.0020.0089.27

preferences:
64.33 ms | 401 KiB | 5 Q