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, $comment, $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.0200.00018.61
8.3.50.0070.01122.05
8.3.40.0120.00318.84
8.3.30.0040.01118.92
8.3.20.0080.00018.90
8.3.10.0080.00021.21
8.3.00.0030.00723.66
8.2.180.0110.00416.88
8.2.170.0150.00022.96
8.2.160.0110.00722.27
8.2.150.0050.00324.18
8.2.140.0040.00424.66
8.2.130.0000.00726.16
8.2.120.0030.00519.67
8.2.110.0030.00620.52
8.2.100.0030.00917.91
8.2.90.0000.00919.20
8.2.80.0040.00418.04
8.2.70.0030.00517.75
8.2.60.0050.00317.93
8.2.50.0040.00418.07
8.2.40.0000.00818.28
8.2.30.0080.00019.48
8.2.20.0000.00817.76
8.2.10.0060.00317.92
8.2.00.0000.00817.99
8.1.280.0120.00625.92
8.1.270.0030.00623.99
8.1.260.0120.00626.35
8.1.250.0100.00028.09
8.1.240.0080.00323.78
8.1.230.0110.00022.12
8.1.220.0050.00318.77
8.1.210.0000.00818.82
8.1.200.0030.00617.35
8.1.190.0070.00017.52
8.1.180.0040.00418.10
8.1.170.0050.00318.54
8.1.160.0050.00218.90
8.1.150.0050.00318.70
8.1.140.0040.00417.56
8.1.130.0000.00717.87
8.1.120.0070.00017.50
8.1.110.0030.00617.52
8.1.100.0000.00817.38
8.1.90.0000.00817.50
8.1.80.0000.00817.49
8.1.70.0000.00817.46
8.1.60.0030.00517.52
8.1.50.0060.00317.44
8.1.40.0050.00317.59
8.1.30.0030.00517.58
8.1.20.0060.00317.54
8.1.10.0000.00817.52
8.1.00.0080.00017.43
8.0.300.0070.00019.98
8.0.290.0040.00417.30
8.0.280.0070.00018.42
8.0.270.0040.00417.32
8.0.260.0000.00716.84
8.0.250.0000.00717.06
8.0.240.0070.00017.13
8.0.230.0000.00717.06
8.0.220.0000.00716.90
8.0.210.0040.00416.87
8.0.200.0000.00716.95
8.0.190.0000.00917.09
8.0.180.0050.00216.91
8.0.170.0050.00316.91
8.0.160.0000.00716.97
8.0.150.0070.00016.94
8.0.140.0000.00816.94
8.0.130.0000.00813.39
8.0.120.0040.00416.92
8.0.110.0000.00717.07
8.0.100.0000.00817.07
8.0.90.0040.00416.88
8.0.80.0030.01516.92
8.0.70.0050.00316.84
8.0.60.0000.00816.96
8.0.50.0060.00316.91
8.0.30.0140.00817.28
8.0.20.0080.01117.40
8.0.10.0040.00417.11
8.0.00.0090.01016.91
7.4.330.0060.00013.43
7.4.320.0040.00416.79
7.4.300.0030.00316.79
7.4.290.0030.00316.79
7.4.280.0030.00316.89
7.4.270.0030.00316.86
7.4.260.0060.00013.54
7.4.250.0000.00816.68
7.4.240.0040.00416.77
7.4.230.0050.00316.65
7.4.220.0150.00316.81
7.4.210.0040.01116.85
7.4.200.0000.00716.88
7.4.190.0000.00816.98
7.4.160.0120.00616.80
7.4.150.0090.00917.40
7.4.140.0110.01017.86
7.4.130.0080.01016.76
7.4.120.0120.00516.75
7.4.110.0060.01616.71
7.4.100.0180.00716.81
7.4.90.0100.01016.95
7.4.80.0160.00319.39
7.4.70.0070.01016.94
7.4.60.0030.01316.84
7.4.50.0000.00716.56
7.4.40.0120.00022.52
7.4.30.0070.01016.92
7.4.00.0040.01315.22
7.3.330.0030.00313.58
7.3.320.0060.00013.69
7.3.310.0000.00716.68
7.3.300.0070.00016.64
7.3.290.0090.00616.55
7.3.280.0090.00916.62
7.3.270.0060.01217.40
7.3.260.0150.01018.24
7.3.250.0120.00516.66
7.3.240.0070.01116.55
7.3.230.0170.00316.93
7.3.210.0130.01016.81
7.3.200.0060.01819.39
7.3.190.0070.01616.85
7.3.180.0030.01216.91
7.3.170.0100.01016.90
7.3.160.0080.00816.89
7.3.120.0030.01215.27
7.3.110.0090.00914.73
7.3.100.0030.01014.79
7.3.90.0060.00915.20
7.3.80.0030.01215.36
7.3.70.0040.00815.02
7.3.60.0040.01214.89
7.3.50.0080.00815.01
7.3.40.0070.00715.04
7.3.30.0070.00715.18
7.3.20.0070.00716.93
7.3.10.0110.00616.68
7.3.00.0040.00717.02
7.2.330.0090.00916.80
7.2.320.0060.01217.13
7.2.310.0100.01316.84
7.2.300.0140.00416.96
7.2.290.0100.00716.91
7.2.250.0030.01615.16
7.2.240.0070.01115.43
7.2.230.0040.01115.52
7.2.220.0090.00615.35
7.2.210.0060.00915.52
7.2.200.0000.01615.14
7.2.190.0080.00815.47
7.2.180.0000.01115.55
7.2.170.0120.00315.41
7.2.110.0220.00916.69
7.2.100.0060.00916.59
7.2.90.0030.01016.55
7.2.80.0170.00716.79
7.2.70.0080.01116.99
7.2.60.0030.01317.01
7.2.50.0070.01117.10
7.2.40.0190.00616.97
7.2.30.0140.00717.03
7.2.20.0130.01417.05
7.2.10.0000.01617.18
7.2.00.0150.00518.28
7.1.330.0150.00015.96
7.1.320.0050.00616.21
7.1.310.0040.00415.90
7.1.300.0100.00716.06
7.1.290.0040.00916.00
7.1.280.0100.00016.10
7.1.270.0040.00816.16
7.1.260.0060.00915.73
7.1.230.0310.00015.90
7.1.220.0140.00016.07
7.1.210.0080.00815.90
7.1.200.0100.00615.95
7.1.190.0070.00715.77
7.1.180.0100.01016.19
7.1.170.0130.00716.07
7.1.160.0100.01115.86
7.1.150.0160.00315.88
7.1.140.0070.01415.85
7.1.130.0130.00715.62
7.1.120.0130.01015.90
7.1.110.0030.01215.58
7.1.100.0120.00416.85
7.1.90.0150.00515.82
7.1.80.0140.00715.92
7.1.70.0110.00416.75
7.1.60.0140.01217.81
7.1.50.0120.01116.67
7.1.40.0170.00316.21
7.1.30.0140.01116.02
7.1.20.0030.01615.95
7.1.10.0070.01015.93
7.1.00.0080.04219.05
7.0.310.0030.00915.40
7.0.300.0070.00715.41
7.0.290.0220.00415.38
7.0.280.0090.01215.47
7.0.270.0160.00315.45
7.0.260.0000.01115.55
7.0.250.0120.00315.43
7.0.240.0150.00615.54
7.0.230.0080.00615.65
7.0.220.0150.00715.39
7.0.210.0060.00915.71
7.0.200.0100.00516.27
7.0.190.0070.00715.62
7.0.180.0170.00315.57
7.0.170.0150.00715.35
7.0.160.0120.00915.65
7.0.150.0090.00615.42
7.0.140.0100.03818.73
7.0.130.0070.00715.53
7.0.120.0180.00415.46
7.0.110.0080.00815.32
7.0.100.0080.00615.69
7.0.90.0100.01015.66
7.0.80.0100.00715.50
7.0.70.0480.04217.73
7.0.60.0420.04017.58
7.0.50.0490.04218.08
7.0.40.0020.03016.87
7.0.30.0080.02816.84
7.0.20.0110.02916.84
7.0.10.0050.02516.80
7.0.00.0070.04216.67
5.6.380.0120.00414.69
5.6.370.0030.01314.61
5.6.360.0060.00914.52
5.6.350.0060.00614.54
5.6.340.0080.00914.70
5.6.330.0150.00014.59
5.6.320.0000.01314.33
5.6.310.0030.01214.54
5.6.300.0030.01214.68
5.6.290.0050.00514.73
5.6.280.0100.03717.63
5.6.270.0030.00714.50
5.6.260.0060.00614.33
5.6.250.0020.01214.16
5.6.240.0000.01214.43
5.6.230.0040.01514.35
5.6.220.0080.02117.55
5.6.210.0080.02917.41
5.6.200.0060.04917.81
5.6.190.0080.04417.75
5.6.180.0100.02717.73
5.6.170.0080.04017.69
5.6.160.0020.03717.57
5.6.150.0080.04717.88
5.6.140.0060.02617.84
5.6.130.0030.02817.70
5.6.120.0050.04917.83
5.6.110.0080.03617.82
5.6.100.0070.03717.63
5.6.90.0030.05217.74
5.6.80.0060.02317.31
5.6.70.0080.03217.39
5.6.60.0140.03817.41
5.6.50.0080.04317.33
5.6.40.0080.03517.52
5.6.30.0030.04717.57
5.6.20.0060.03017.43
5.6.10.0070.03417.42
5.6.00.0080.02517.48
5.5.380.0000.01011.02
5.5.370.0050.00511.46
5.5.360.0080.04215.90
5.5.350.0100.04015.75
5.5.340.0070.04316.17
5.5.330.0030.04815.96
5.5.320.0050.04216.04
5.5.310.0060.04316.09
5.5.300.0070.04516.05
5.5.290.0080.02316.05
5.5.280.0050.02615.97
5.5.270.0050.04515.95
5.5.260.0080.04316.19
5.5.250.0080.03215.88
5.5.240.0050.03515.58
5.5.230.0080.04315.56
5.5.220.0070.02315.77
5.5.210.0080.04115.86
5.5.200.0110.03115.78
5.5.190.0050.03315.72
5.5.180.0080.04315.87
5.5.170.0070.00714.31
5.5.160.0090.03215.84
5.5.150.0090.03715.77
5.5.140.0110.03815.80
5.5.130.0020.04015.76
5.5.120.0080.04215.81
5.5.110.0070.02715.76
5.5.100.0050.03215.63
5.5.90.0060.02815.68
5.5.80.0080.04115.73
5.5.70.0100.03815.81
5.5.60.0020.04315.74
5.5.50.0080.04015.85
5.5.40.0060.02715.59
5.5.30.0070.04315.54
5.5.20.0070.03915.58
5.5.10.0030.04815.55
5.5.00.0050.04015.66
5.4.450.0080.03515.26
5.4.440.0050.04215.41
5.4.430.0070.04315.25
5.4.420.0100.03015.29
5.4.410.0050.04315.39
5.4.400.0050.03715.16
5.4.390.0050.02714.97
5.4.380.0050.04415.18
5.4.370.0120.03615.05
5.4.360.0030.04815.14
5.4.350.0030.04515.34
5.4.340.0050.04615.23
5.4.330.0030.00511.37
5.4.320.0090.01915.24
5.4.310.0020.04915.00
5.4.300.0070.03815.38
5.4.290.0030.04314.94
5.4.280.0070.04215.15
5.4.270.0020.03415.17
5.4.260.0070.03015.33
5.4.250.0050.04315.00
5.4.240.0050.04015.26
5.4.230.0020.03315.21
5.4.220.0080.04215.04
5.4.210.0100.03515.22
5.4.200.0110.03815.19
5.4.190.0050.04215.08
5.4.180.0120.03715.12
5.4.170.0070.03915.06
5.4.160.0050.03315.07
5.4.150.0080.04114.96
5.4.140.0100.03513.89
5.4.130.0030.04113.81
5.4.120.0070.03913.90
5.4.110.0120.03413.80
5.4.100.0060.04314.07
5.4.90.0070.03013.68
5.4.80.0100.03513.71
5.4.70.0100.02013.85
5.4.60.0080.03613.91
5.4.50.0060.04113.88
5.4.40.0090.02013.86
5.4.30.0050.03013.95
5.4.20.0080.03613.82
5.4.10.0010.02613.84
5.4.00.0030.04113.30
5.3.290.0080.03712.83
5.3.280.0070.04412.74
5.3.270.0090.03812.74
5.3.260.0080.03912.77
5.3.250.0060.04012.81
5.3.240.0030.03312.66
5.3.230.0030.04512.71
5.3.220.0050.04412.66
5.3.210.0070.02812.67
5.3.200.0050.03212.64
5.3.190.0040.02412.66
5.3.180.0070.02912.75
5.3.170.0010.02912.72
5.3.160.0100.03812.80
5.3.150.0030.02912.75
5.3.140.0060.03312.71
5.3.130.0040.02612.70
5.3.120.0110.03812.74
5.3.110.0030.03812.77
5.3.100.0060.03312.42
5.3.90.0110.02712.37
5.3.80.0090.03912.33
5.3.70.0050.04412.30
5.3.60.0100.03812.27
5.3.50.0060.03812.21
5.3.40.0080.04012.30
5.3.30.0050.03812.28
5.3.20.0050.04312.24
5.3.10.0060.04012.09
5.3.00.0050.03212.09
5.2.170.0060.02310.82
5.2.160.0070.03410.85
5.2.150.0050.03310.94
5.2.140.0060.03110.79
5.2.130.0020.03810.73
5.2.120.0050.02710.93
5.2.110.0030.03510.91
5.2.100.0090.03010.87
5.2.90.0030.03610.72
5.2.80.0060.03110.84
5.2.70.0010.03810.86
5.2.60.0070.03510.72
5.2.50.0060.02510.82
5.2.40.0030.03310.85
5.2.30.0050.03310.87
5.2.20.0030.03710.82
5.2.10.0060.03110.78
5.2.00.0050.02910.73
5.1.60.0070.02110.37
5.1.50.0070.02810.40
5.1.40.0040.02110.43
5.1.30.0030.02010.48
5.1.20.0070.02810.52
5.1.10.0080.02610.48
5.1.00.0030.03110.34
5.0.50.0050.01810.21
5.0.40.0060.02010.21
5.0.30.0060.02610.21
5.0.20.0050.02210.21
5.0.10.0040.02310.21
5.0.00.0050.02210.21
4.4.90.0000.01610.21
4.4.80.0040.01610.21
4.4.70.0020.01810.21
4.4.60.0020.02210.21
4.4.50.0020.02010.21
4.4.40.0020.02810.21
4.4.30.0010.01510.21
4.4.20.0010.02010.21
4.4.10.0030.01710.21
4.4.00.0000.03210.21
4.3.110.0040.01910.21
4.3.100.0040.01810.21
4.3.90.0030.01510.21
4.3.80.0030.02810.21
4.3.70.0000.02310.21
4.3.60.0030.01810.21
4.3.50.0050.01310.21
4.3.40.0010.02510.21
4.3.30.0020.01810.21
4.3.20.0050.01810.21
4.3.10.0050.01310.21
4.3.00.0020.02010.21

preferences:
46.64 ms | 401 KiB | 5 Q