note 115086 added to function.filter-input

From: Date: Fri, 23 May 2014 13:22:36 +0000
Subject: note 115086 added to function.filter-input
Groups: php.notes 
Request: Send a blank email to php-notes+get-199605@lists.php.net to get a copy of this message
This function provides us the extremely simple solution for type filtering. Without this function... <?php if (!isset($_GET['a'])) { $a = null; } elseif (!is_string($_GET['a'])) { $a = false; } else { $a = $_GET['a']; } $b = isset($_GET['b']) && is_string($_GET['b']) ? $_GET['b'] : ''; ?> With this function... <?php $a = filter_input(INPUT_GET, 'a'); $b = (string)filter_input(INPUT_GET, 'b'); ?> Yes, FILTER_REQUIRE_SCALAR seems to be set as a default option. It's very helpful for eliminating E_NOTICE, E_WARNING and E_ERROR. This fact should be documented. ---- Server IP: 72.52.91.14 Probable Submitter: 133.68.187.151 ---- Manual Page -- http://php.net/manual/en/function.filter-input.php Edit -- https://master.php.net/note/edit/115086 Del: integrated -- https://master.php.net/note/delete/115086/integrated Del: useless -- https://master.php.net/note/delete/115086/useless Del: bad code -- https://master.php.net/note/delete/115086/bad+code Del: spam -- https://master.php.net/note/delete/115086/spam Del: non-english -- https://master.php.net/note/delete/115086/non-english Del: in docs -- https://master.php.net/note/delete/115086/in+docs Del: other reasons-- https://master.php.net/note/delete/115086 Reject -- https://master.php.net/note/reject/115086 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#199605) next »