3v4l.org

run code in 300+ PHP versions simultaneously
<? 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 git.master, git.master_jit, rfc.property-hooks
<? 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);

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
39.05 ms | 404 KiB | 8 Q