3v4l.org

run code in 300+ PHP versions simultaneously
<?php function filter_input_utf8($type, $default = array()) { static $is_recursive_static = false; $is_recursive = $is_recursive_static; if (!$is_recursive_static) { $types = array( INPUT_GET => $_GET, INPUT_POST => $_POST, INPUT_COOKIE => $_COOKIE, INPUT_REQUEST => $_REQUEST, INPUT_ENV => $_ENV, INPUT_SERVER => $_SERVER, ); if (!isset($types[$type])) { return $default; } $var = $types[$type]; $is_recursive_static = true; } else { $var = $type; } $ret = array(); foreach ((array)$default as $key => $value) { if (!isset($var[$key])) { $ret[$key] = $value; } elseif (is_array($value)) { $ret[$key] = filter_input_utf8($var[$key], $value); } elseif (is_array($var[$key]) || !preg_match('//u', $var)) { $ret[$key] = $value; } else { $ret[$key] = $var[$key]; } } if (!$is_recursive) { $is_recursive_static = false; } return $ret; } $_POST = array( 'a' => array( 'b' => 'Invalid Data', ), 'c' => array( 'd' => 'Valid Data', ), 'e' => 'Valid Data', 'f' => 'Unneeded Data', ); $post = filter_input_utf8($_POST, array( 'a' => null, 'c' => array( 'd' => null, ), 'e' => null, )); var_dump($post);
Output for 8.2.0 - 8.2.18, 8.3.0 - 8.3.6
Fatal error: Uncaught Error: Undefined constant "INPUT_REQUEST" in /in/9g2pR:10 Stack trace: #0 /in/9g2pR(49): filter_input_utf8(Array, Array) #1 {main} thrown in /in/9g2pR on line 10
Process exited with code 255.
Output for 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Fatal error: Uncaught Error: Undefined constant "INPUT_REQUEST" in /in/9g2pR:10 Stack trace: #0 /in/9g2pR(50): filter_input_utf8(Array, Array) #1 {main} thrown in /in/9g2pR on line 10
Process exited with code 255.
Output for 5.2.0 - 5.2.17, 5.3.0 - 5.3.29, 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
Warning: Illegal offset type in isset or empty in /in/9g2pR on line 14 array(3) { ["a"]=> NULL ["c"]=> array(1) { ["d"]=> NULL } ["e"]=> NULL }
Output for 5.1.0 - 5.1.6
Notice: Use of undefined constant INPUT_GET - assumed 'INPUT_GET' in /in/9g2pR on line 7 Notice: Use of undefined constant INPUT_POST - assumed 'INPUT_POST' in /in/9g2pR on line 8 Notice: Use of undefined constant INPUT_COOKIE - assumed 'INPUT_COOKIE' in /in/9g2pR on line 9 Notice: Use of undefined constant INPUT_REQUEST - assumed 'INPUT_REQUEST' in /in/9g2pR on line 10 Notice: Use of undefined constant INPUT_ENV - assumed 'INPUT_ENV' in /in/9g2pR on line 11 Notice: Use of undefined constant INPUT_SERVER - assumed 'INPUT_SERVER' in /in/9g2pR on line 12 Warning: Illegal offset type in isset or empty in /in/9g2pR on line 14 array(3) { ["a"]=> NULL ["c"]=> array(1) { ["d"]=> NULL } ["e"]=> NULL }
Output for 5.0.0 - 5.0.5
Notice: Use of undefined constant INPUT_GET - assumed 'INPUT_GET' in /in/9g2pR on line 7 Notice: Use of undefined constant INPUT_POST - assumed 'INPUT_POST' in /in/9g2pR on line 8 Notice: Use of undefined constant INPUT_COOKIE - assumed 'INPUT_COOKIE' in /in/9g2pR on line 9 Notice: Use of undefined constant INPUT_REQUEST - assumed 'INPUT_REQUEST' in /in/9g2pR on line 10 Notice: Use of undefined constant INPUT_ENV - assumed 'INPUT_ENV' in /in/9g2pR on line 11 Notice: Use of undefined constant INPUT_SERVER - assumed 'INPUT_SERVER' in /in/9g2pR on line 12 Warning: Illegal offset type in unset in /in/9g2pR on line 14 array(3) { ["a"]=> NULL ["c"]=> array(1) { ["d"]=> NULL } ["e"]=> NULL }
Output for 4.3.0 - 4.3.11, 4.4.0 - 4.4.9
Notice: Use of undefined constant INPUT_GET - assumed 'INPUT_GET' in /in/9g2pR on line 7 Notice: Use of undefined constant INPUT_POST - assumed 'INPUT_POST' in /in/9g2pR on line 8 Notice: Use of undefined constant INPUT_COOKIE - assumed 'INPUT_COOKIE' in /in/9g2pR on line 9 Notice: Use of undefined constant INPUT_REQUEST - assumed 'INPUT_REQUEST' in /in/9g2pR on line 10 Notice: Use of undefined constant INPUT_ENV - assumed 'INPUT_ENV' in /in/9g2pR on line 11 Notice: Use of undefined constant INPUT_SERVER - assumed 'INPUT_SERVER' in /in/9g2pR on line 12 Warning: Illegal offset type in /in/9g2pR on line 14 array(3) { ["a"]=> NULL ["c"]=> array(1) { ["d"]=> NULL } ["e"]=> NULL }

preferences:
271.76 ms | 403 KiB | 460 Q