Req #54852 [Com]: Add filter option to allow both arrays and scalars
| From: | design at gresak dot net | Date: | Mon, 27 Jan 2014 17:01:36 +0000 |
| Subject: | Req #54852 [Com]: Add filter option to allow both arrays and scalars | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184036@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=54852&edit=1
ID: 54852
Comment by: design at gresak dot net
Reported by: phrisyen at yahoo dot com
Summary: Add filter option to allow both arrays and scalars
Status: Open
Type: Feature/Change Request
Package: Filter related
Operating System: *
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
I can't filter an array value (comming from a set of checkboxes) with input_filter.
Reproduction:
var_dump($_POST['options'], filter_input(INPUT_POST, 'options'));
Result:
array(2) {
[1]=>
string(5) "first"
[2]=>
string(6) "second"
}
bool(false)
Previous Comments:
------------------------------------------------------------------------
[2011-05-19 05:27:16] phrisyen at yahoo dot com
Description:
------------
This is a request for adding another flag (FILTER_FLAG_ALLOW_ARRAY) to filter extension to allow
both arrays and scalars for input, while retaining their type (as opposed to FILTER_FORCE_ARRAY,
which can accept scalars, but will return an array).
So if input is array, return an array, and if scalar, return scalar.
It seems pretty basic.
Test script:
---------------
$test = filter_input(INPUT_GET, "a", FILTER_VALIDATE_INT, FILTER_FLAG_ALLOW_ARRAY);
var_dump($test);
Expected result:
----------------
test.php?a=1
int(1)
test.php?a[]=1&a[]=2
array (2) { [0] => int(1), [1] => int(2) }
Actual result:
--------------
FILTER_FLAG_ALLOW_ARRAY not implemented ;)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=54852&edit=1