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_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.40.0070.00718.79
8.3.30.0140.00718.92
8.3.20.0040.00418.83
8.3.10.0080.00020.53
8.3.00.0060.00317.75
8.2.170.0090.00922.96
8.2.160.0100.00322.08
8.2.150.0060.00324.18
8.2.140.0000.00824.66
8.2.130.0050.00326.16
8.2.120.0040.00419.83
8.2.110.0030.00621.18
8.2.100.0040.01117.84
8.2.90.0000.00819.21
8.2.80.0040.00418.16
8.2.70.0000.01117.75
8.2.60.0100.00318.05
8.2.50.0000.00818.07
8.2.40.0000.00818.28
8.2.30.0040.00418.23
8.2.20.0080.00017.89
8.2.10.0000.00817.80
8.2.00.0000.00817.99
8.1.270.0080.00023.99
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0100.00022.64
8.1.230.0120.00020.88
8.1.220.0000.00818.77
8.1.210.0000.00818.90
8.1.200.0030.00717.48
8.1.190.0030.00517.53
8.1.180.0090.00018.10
8.1.170.0050.00318.89
8.1.160.0040.00418.89
8.1.150.0040.00418.75
8.1.140.0040.00417.56
8.1.130.0050.00217.42
8.1.120.0040.00417.54
8.1.110.0000.00717.47
8.1.100.0050.00317.43
8.1.90.0040.00417.55
8.1.80.0080.00017.57
8.1.70.0030.00317.52
8.1.60.0050.00317.64
8.1.50.0060.00317.56
8.1.40.0050.00317.55
8.1.30.0080.00017.76
8.1.20.0030.00617.58
8.1.10.0050.00317.60
8.1.00.0000.00817.46
8.0.300.0040.00420.09
8.0.290.0030.00816.88
8.0.280.0000.00718.37
8.0.270.0000.00817.21
8.0.260.0050.00316.88
8.0.250.0000.00716.96
8.0.240.0000.00917.07
8.0.230.0000.00816.98
8.0.220.0030.00316.92
8.0.210.0070.00016.89
8.0.200.0000.00617.09
8.0.190.0000.00717.05
8.0.180.0040.00416.93
8.0.170.0040.00417.04
8.0.160.0000.00716.97
8.0.150.0040.00416.86
8.0.140.0090.00316.89
8.0.130.0000.00613.44
8.0.120.0050.00316.89
8.0.110.0000.00816.88
8.0.100.0000.00716.82
8.0.90.0040.00416.95
8.0.80.0000.01517.06
8.0.70.0040.00417.07
8.0.60.0000.00717.13
8.0.50.0030.00516.96
8.0.30.0050.01517.13
8.0.20.0080.01517.29
8.0.10.0000.00817.11
8.0.00.0080.01116.96
7.4.330.0030.00314.86
7.4.320.0060.00016.84
7.4.300.0040.00416.92
7.4.290.0000.00716.68
7.4.280.0100.00016.75
7.4.270.0000.00716.79
7.4.260.0060.00013.44
7.4.250.0030.00516.87
7.4.240.0040.00416.66
7.4.230.0000.00716.98
7.4.220.0140.00516.73
7.4.210.0120.00516.91
7.4.200.0050.00316.91
7.4.190.0040.00416.91
7.4.160.0100.00616.88
7.4.150.0090.00917.07
7.4.140.0100.00717.31
7.4.130.0120.00616.84
7.4.120.0130.00816.89
7.4.110.0100.01316.72
7.4.100.0090.00916.78
7.4.90.0110.00716.77
7.4.80.0150.01018.80
7.4.70.0060.01316.48
7.4.60.0030.01416.71
7.4.50.0040.00416.42
7.4.40.0120.00622.27
7.4.30.0070.01316.73
7.4.00.0070.00715.38
7.3.330.0030.00313.51
7.3.320.0060.00013.52
7.3.310.0040.00416.48
7.3.300.0000.00716.49
7.3.290.0140.00716.62
7.3.280.0100.00916.64
7.3.270.0110.01417.18
7.3.260.0160.00718.24
7.3.250.0150.00616.66
7.3.240.0090.00916.48
7.3.230.0060.01016.91
7.3.210.0150.00316.79
7.3.200.0130.00519.39
7.3.190.0040.01416.68
7.3.180.0110.01116.68
7.3.170.0160.00016.52
7.3.160.0150.00816.70
7.3.120.0060.00915.29
7.2.330.0060.01217.04
7.2.320.0150.00916.84
7.2.310.0060.01217.09
7.2.300.0110.01416.91
7.2.290.0040.01416.89
7.2.00.0040.01119.85
7.1.100.0030.01018.18
7.1.70.0070.00017.41
7.1.60.0140.01019.40
7.1.50.0000.02016.96
7.1.00.0030.06722.46
7.0.200.0070.00316.68
7.0.140.0000.07722.08
7.0.60.0100.06319.90
7.0.50.0070.08017.85
7.0.40.0070.06017.78
7.0.30.0170.07017.77
7.0.20.0100.04317.78
7.0.10.0070.04717.83
7.0.00.0070.04717.77
5.6.210.0030.09020.74
5.6.200.0100.05018.26
5.6.190.0170.07318.14
5.6.180.0070.07018.19
5.6.170.0070.06318.29
5.6.160.0070.06318.14
5.6.150.0100.08018.16
5.6.140.0100.04718.30
5.6.130.0100.04018.21
5.6.120.0000.07718.18
5.6.110.0030.04718.18
5.6.100.0100.05718.26
5.6.90.0070.06718.14
5.6.80.0070.06317.66
5.6.70.0170.05317.52
5.6.60.0070.05717.65
5.6.50.0070.04717.57
5.6.40.0030.04717.63
5.6.30.0070.03717.55
5.6.20.0070.03717.51
5.6.10.0030.08017.51
5.6.00.0130.07017.63
5.5.350.0330.07020.45
5.5.340.0200.05717.99
5.5.330.0070.04317.95
5.5.320.0100.04318.05
5.5.310.0030.05717.94
5.5.300.0270.02718.05
5.5.290.0070.08317.99
5.5.280.0100.04017.99
5.5.270.0030.08317.96
5.5.260.0030.06318.01
5.5.250.0000.04317.89
5.5.240.0030.04017.35
5.5.230.0070.07317.33
5.5.220.0030.04017.33
5.5.210.0070.07717.32
5.5.200.0070.06717.41
5.5.190.0070.04317.34
5.5.180.0070.08017.33
5.5.160.0070.06317.32
5.5.150.0100.06717.41
5.5.140.0100.04317.34
5.5.130.0070.08017.30
5.5.120.0030.05317.36
5.5.110.0070.04017.39
5.5.100.0070.06317.34
5.5.90.0100.04317.20
5.5.80.0070.06017.26
5.5.70.0030.06717.31
5.5.60.0030.08317.23
5.5.50.0030.04717.20
5.5.40.0070.04017.21
5.5.30.0070.03717.18
5.5.20.0030.04017.29
5.5.10.0030.06317.32
5.5.00.0100.04717.21
5.4.450.0270.06319.39
5.4.440.0100.03319.42
5.4.430.0000.05319.44
5.4.420.0000.04319.37
5.4.410.0030.04319.21
5.4.400.0030.04019.04
5.4.390.0100.05319.14
5.4.380.0100.05719.27
5.4.370.0100.06719.05
5.4.360.0070.07719.14
5.4.350.0000.05719.27
5.4.340.0070.04019.10
5.4.320.0070.07318.89
5.4.310.0030.05719.13
5.4.300.0070.06019.04
5.4.290.0100.07018.95
5.4.280.0070.07318.88
5.4.270.0030.04319.05
5.4.260.0030.08318.89
5.4.250.0030.05019.09
5.4.240.0230.06319.13
5.4.230.0030.08018.88
5.4.220.0100.07319.04
5.4.210.0070.07318.98
5.4.200.0000.04319.04
5.4.190.0070.04319.00
5.4.180.0170.06719.00
5.4.170.0130.06719.00
5.4.160.0170.04319.02
5.4.150.0070.07719.02
5.4.140.0130.07016.36
5.4.130.0130.06016.37
5.4.120.0100.04016.43
5.4.110.0000.06716.28
5.4.100.0130.05316.43
5.4.90.0200.06316.50
5.4.80.0170.06016.51
5.4.70.0000.08016.50
5.4.60.0100.04316.42
5.4.50.0070.07016.53
5.4.40.0100.04016.27
5.4.30.0070.07716.48
5.4.20.0030.06316.32
5.4.10.0070.04316.41
5.4.00.0070.06015.85
5.3.290.0030.07314.76
5.3.280.0070.03714.62
5.3.270.0130.07014.70
5.3.260.0100.07314.71
5.3.250.0100.04714.67
5.3.240.0070.07314.74
5.3.230.0030.05314.71
5.3.220.0000.07714.66
5.3.210.0070.06014.66
5.3.200.0030.05314.81
5.3.190.0130.05014.63
5.3.180.0170.05714.66
5.3.170.0170.05314.59
5.3.160.0070.07714.66
5.3.150.0030.04014.64
5.3.140.0030.04014.54
5.3.130.0130.07014.70
5.3.120.0100.07314.58
5.3.110.0030.08014.63
5.3.100.0170.06714.09
5.3.90.0070.07314.12
5.3.80.0030.03714.16
5.3.70.0000.04314.14
5.3.60.0000.07313.93
5.3.50.0070.06313.88
5.3.40.0070.07714.02
5.3.30.0100.04713.99
5.3.20.0030.04313.62
5.3.10.0130.05013.68
5.3.00.0100.06713.87
5.2.170.0070.06311.26
5.2.160.0130.05711.26
5.2.150.0100.06011.26
5.2.140.0070.03311.26
5.2.130.0030.03711.26
5.2.120.0100.05711.26
5.2.110.0100.03011.26
5.2.100.0070.06311.26
5.2.90.0030.04011.26
5.2.80.0100.06011.26
5.2.70.0000.06711.26
5.2.60.0000.06711.26
5.2.50.0100.06311.26
5.2.40.0100.03011.26
5.2.30.0130.05311.26
5.2.20.0030.04711.26
5.2.10.0070.05711.26
5.2.00.0100.05011.26
5.1.60.0100.03311.26
5.1.50.0030.05311.26
5.1.40.0100.04711.26
5.1.30.0030.05711.26
5.1.20.0030.03311.26
5.1.10.0000.03311.26
5.1.00.0030.03711.26
5.0.50.0030.04711.26
5.0.40.0000.04711.26
5.0.30.0000.06711.26
5.0.20.0070.04311.26
5.0.10.0070.02011.26
5.0.00.0030.04711.26
4.4.90.0000.03711.26
4.4.80.0000.02711.26
4.4.70.0070.03311.26
4.4.60.0030.02311.26
4.4.50.0030.03311.26
4.4.40.0030.03311.26
4.4.30.0070.01711.26
4.4.20.0000.02011.26
4.4.10.0070.02711.26
4.4.00.0070.05311.26
4.3.110.0030.03711.26
4.3.100.0030.03711.26
4.3.90.0030.02711.26
4.3.80.0100.04711.26
4.3.70.0030.03711.26
4.3.60.0070.03311.26
4.3.50.0000.04011.26
4.3.40.0130.03711.26
4.3.30.0030.03711.26
4.3.20.0000.03711.26
4.3.10.0000.02711.26
4.3.00.0030.03711.26

preferences:
41.66 ms | 400 KiB | 5 Q