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\x0a This is invalid encoding value", "\x0a\x0a\x0a" => '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 | FIRTER_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.0100.01018.53
8.3.50.0110.00921.14
8.3.40.0110.00418.96
8.3.30.0110.00418.93
8.3.20.0040.00418.71
8.3.10.0000.00821.23
8.3.00.0040.00421.73
8.2.180.0150.00016.88
8.2.170.0130.00722.96
8.2.160.0100.00320.54
8.2.150.0030.00624.18
8.2.140.0040.00424.66
8.2.130.0080.00026.16
8.2.120.0000.00721.04
8.2.110.0030.00621.12
8.2.100.0060.00617.97
8.2.90.0080.00019.17
8.2.80.0040.00417.97
8.2.70.0040.00417.75
8.2.60.0030.00517.93
8.2.50.0100.00318.07
8.2.40.0000.00818.34
8.2.30.0060.00321.13
8.2.20.0000.00817.89
8.2.10.0040.00417.98
8.2.00.0000.00817.91
8.1.280.0140.00425.92
8.1.270.0060.00323.99
8.1.260.0060.00326.35
8.1.250.0030.00628.09
8.1.240.0060.00322.06
8.1.230.0070.00320.79
8.1.220.0040.00417.79
8.1.210.0000.00918.77
8.1.200.0000.00917.35
8.1.190.0080.00017.66
8.1.180.0060.00318.10
8.1.170.0000.00818.65
8.1.160.0040.00418.89
8.1.150.0040.00418.73
8.1.140.0000.00917.44
8.1.130.0070.00017.75
8.1.120.0000.00717.55
8.1.110.0060.00317.42
8.1.100.0030.00517.46
8.1.90.0030.00517.53
8.1.80.0080.00017.49
8.1.70.0000.00717.49
8.1.60.0030.00617.63
8.1.50.0040.00417.41
8.1.40.0060.00317.52
8.1.30.0050.00317.71
8.1.20.0080.00017.68
8.1.10.0000.00817.64
8.1.00.0120.00017.53
8.0.300.0050.00518.77
8.0.290.0040.00416.88
8.0.280.0080.00018.39
8.0.270.0070.00017.18
8.0.260.0050.00316.85
8.0.250.0050.00217.00
8.0.240.0060.00317.10
8.0.230.0000.00717.00
8.0.220.0040.00416.84
8.0.210.0000.00717.05
8.0.200.0000.00617.09
8.0.190.0000.00717.08
8.0.180.0040.00417.04
8.0.170.0000.00816.92
8.0.160.0040.00417.00
8.0.150.0000.00716.97
8.0.140.0050.00217.02
8.0.130.0000.00613.52
8.0.120.0000.00716.84
8.0.110.0000.00717.01
8.0.100.0000.00717.07
8.0.90.0050.00517.05
8.0.80.0130.00717.05
8.0.70.0060.00317.07
8.0.60.0000.00716.88
8.0.50.0000.00716.95
8.0.30.0090.01017.16
8.0.20.0090.01517.40
8.0.10.0050.00217.20
8.0.00.0120.00916.88
7.4.330.0050.00014.86
7.4.320.0030.00316.88
7.4.300.0000.00616.87
7.4.290.0050.00316.90
7.4.280.0000.00716.77
7.4.270.0040.00416.76
7.4.260.0030.00313.52
7.4.250.0030.00516.72
7.4.240.0060.00316.77
7.4.230.0000.00716.88
7.4.220.0040.02216.81
7.4.210.0100.00916.82
7.4.200.0070.00016.69
7.4.190.0000.00916.82
7.4.160.0170.00016.82
7.4.150.0110.00717.40
7.4.140.0100.00817.86
7.4.130.0080.01016.64
7.4.120.0090.00916.96
7.4.110.0140.00516.93
7.4.100.0110.00716.83
7.4.90.0170.00316.82
7.4.80.0100.00719.39
7.4.70.0090.00916.96
7.4.60.0030.01716.75
7.4.50.0040.00416.96
7.4.40.0120.00422.77
7.4.30.0080.00816.80
7.4.00.0100.00815.26
7.3.330.0030.00313.64
7.3.320.0060.00013.71
7.3.310.0040.00416.50
7.3.300.0000.00716.73
7.3.290.0100.01016.70
7.3.280.0080.00816.60
7.3.270.0080.00817.40
7.3.260.0070.01318.24
7.3.250.0050.01216.88
7.3.240.0130.00716.88
7.3.230.0120.00616.71
7.3.210.0090.00917.01
7.3.200.0030.01919.39
7.3.190.0090.01216.71
7.3.180.0080.00816.76
7.3.170.0070.01116.83
7.3.160.0060.01216.85
7.3.120.0050.01215.01
7.3.110.0020.01615.12
7.3.100.0020.01315.12
7.3.90.0040.00815.06
7.3.80.0120.00315.07
7.3.70.0100.00414.88
7.3.60.0060.01015.06
7.3.50.0060.01015.00
7.3.40.0050.01014.90
7.3.30.0030.01215.12
7.3.20.0050.00716.82
7.3.10.0030.00916.93
7.3.00.0070.00816.80
7.2.330.0090.00917.00
7.2.320.0040.01416.92
7.2.310.0120.00817.04
7.2.300.0160.00616.97
7.2.290.0120.00616.86
7.2.250.0040.01515.54
7.2.240.0090.00615.23
7.2.230.0050.01015.21
7.2.220.0020.01115.18
7.2.210.0070.00915.57
7.2.200.0050.00815.41
7.2.190.0090.00715.47
7.2.180.0070.01015.45
7.2.170.0090.00815.36
7.2.160.0060.00915.27
7.2.150.0120.00617.17
7.2.140.0090.00616.91
7.2.130.0000.01417.27
7.2.120.0070.00717.10
7.2.110.0030.01316.99
7.2.100.0030.01016.93
7.2.90.0120.00017.19
7.2.80.0060.00916.93
7.2.70.0030.01317.23
7.2.60.0050.01216.95
7.2.50.0040.00817.27
7.2.40.0030.01217.32
7.2.30.0100.00317.29
7.2.20.0080.00817.27
7.2.10.0090.00617.10
7.2.00.0050.00718.41
7.1.330.0060.00615.86
7.1.320.0100.00416.03
7.1.310.0040.01116.04
7.1.300.0050.00915.86
7.1.290.0020.01315.79
7.1.280.0050.01016.05
7.1.270.0100.00716.10
7.1.260.0060.01015.85
7.1.250.0040.01216.09
7.1.200.0060.00615.84
7.1.100.0060.00618.40
7.1.70.0040.00417.52
7.1.60.0030.02119.40
7.1.50.0060.01817.26
7.1.00.0030.03322.44
7.0.200.0070.00316.73
7.0.140.0000.07722.00
7.0.60.0070.04720.09
7.0.50.0130.07717.84
7.0.40.0130.07720.31
7.0.30.0400.04720.30
7.0.20.0370.07720.09
7.0.10.0300.04020.11
7.0.00.0070.04020.16
5.6.280.0070.07021.09
5.6.210.0000.04320.52
5.6.200.0000.04318.15
5.6.190.0030.06720.48
5.6.180.0230.04720.53
5.6.170.0270.07720.45
5.6.160.0070.07020.39
5.6.150.0100.07018.19
5.6.140.0170.07318.21
5.6.130.0100.07318.28
5.6.120.0100.05320.92
5.6.110.0200.07021.04
5.6.100.0270.06721.01
5.6.90.0070.08321.02
5.6.80.0030.08020.43
5.6.70.0370.07320.40
5.5.350.0400.04020.36
5.5.340.0000.09017.96
5.5.330.0000.09020.40
5.5.320.0300.08020.35
5.5.310.0230.05720.34
5.5.300.0070.08017.99
5.5.290.0100.08317.94
5.5.280.0070.08320.90
5.5.270.0030.05020.98
5.5.260.0030.04020.87
5.5.250.0100.03320.71
5.5.240.0170.06020.26
5.4.450.0370.06719.64
5.4.440.0170.04719.39
5.4.430.0200.03019.26
5.4.420.0070.07319.51
5.4.410.0130.04319.39
5.4.400.0130.03718.88
5.4.390.0200.04019.24
5.4.380.0170.03319.09
5.4.370.0170.04019.23
5.4.360.0130.03719.22
5.4.350.0200.03019.15
5.4.340.0130.03719.00
5.4.320.0130.03719.01
5.4.310.0170.04719.32
5.4.300.0170.03319.08
5.4.290.0100.04719.18
5.4.280.0100.04019.21
5.4.270.0230.06319.21
5.4.260.0230.05319.22
5.4.250.0300.06019.30
5.4.240.0170.07719.09
5.4.230.0200.06719.14
5.4.220.0230.04318.97
5.4.210.0200.05719.19
5.4.200.0200.06319.25
5.4.190.0300.06719.18
5.4.180.0370.06318.94
5.4.170.0200.05319.14
5.4.160.0200.06318.83
5.4.150.0200.03719.23
5.4.140.0230.04016.41
5.4.130.0270.06016.40
5.4.120.0300.06016.55
5.4.110.0170.04316.42
5.4.100.0170.03716.61
5.4.90.0270.02716.61
5.4.80.0330.05716.62
5.4.70.0270.07316.48
5.4.60.0330.05716.56
5.4.50.0100.05316.53
5.4.40.0130.05316.19
5.4.30.0330.06316.48
5.4.20.0270.07316.19
5.4.10.0030.05016.54
5.4.00.0100.06015.98
5.3.290.0100.04314.94
5.3.280.0270.05714.55
5.3.270.0300.03314.72
5.3.260.0230.05714.66
5.3.250.0300.03714.64
5.3.240.0170.04314.62
5.3.230.0330.06314.71
5.3.220.0270.04014.65
5.3.210.0200.08014.60
5.3.200.0200.04314.53
5.3.190.0270.06714.50
5.3.180.0230.04014.57
5.3.170.0300.03314.50
5.3.160.0200.05014.60
5.3.150.0230.05014.66
5.3.140.0230.03314.57
5.3.130.0230.04314.74
5.3.120.0270.07014.59
5.3.110.0230.06314.70
5.3.100.0270.06013.99
5.3.90.0270.07013.95
5.3.80.0170.05014.06
5.3.70.0300.06714.13
5.3.60.0270.05313.96
5.3.50.0230.04313.90
5.3.40.0330.05013.89
5.3.30.0270.06714.17
5.3.20.0130.05313.65
5.3.10.0200.05313.55
5.3.00.0300.06313.89
5.2.170.0270.05311.89
5.2.160.0200.05311.89
5.2.150.0230.05311.89
5.2.140.0200.04711.89
5.2.130.0200.03711.89
5.2.120.0200.05711.89
5.2.110.0170.05711.89
5.2.100.0270.05011.89
5.2.90.0130.04011.89
5.2.80.0170.04011.89
5.2.70.0170.03711.89
5.2.60.0230.05711.89
5.2.50.0170.06311.89
5.2.40.0200.05711.89
5.2.30.0170.06011.89
5.2.20.0230.03711.89
5.2.10.0200.04711.89
5.2.00.0230.04011.89
5.1.60.0200.04311.89
5.1.50.0070.03311.89
5.1.40.0170.03311.89
5.1.30.0170.05311.89
5.1.20.0230.03011.89
5.1.10.0130.04011.89
5.1.00.0170.05311.91
5.0.50.0100.03011.94
5.0.40.0100.02711.94
5.0.30.0070.03011.95
5.0.20.0100.04311.96
5.0.10.0070.02311.97
5.0.00.0030.03311.97
4.4.90.0070.03711.89
4.4.80.0100.03011.89
4.4.70.0100.03011.89
4.4.60.0100.03311.89
4.4.50.0130.03011.89
4.4.40.0070.02711.89
4.4.30.0230.02311.89
4.4.20.0100.02311.89
4.4.10.0170.03011.94
4.4.00.0100.03011.94
4.3.110.0100.01311.95
4.3.100.0030.03011.96
4.3.90.0100.01711.96
4.3.80.0030.02711.98
4.3.70.0100.01711.99
4.3.60.0100.01711.99
4.3.50.0070.01712.00
4.3.40.0070.03012.00
4.3.30.0070.02012.00
4.3.20.0030.02712.00
4.3.10.0030.02712.01
4.3.00.0000.02712.01

preferences:
37.26 ms | 401 KiB | 5 Q