php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #54852 Add filter option to allow both arrays and scalars
Submitted: 2011-05-19 05:27 UTC Modified: -
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: phrisyen at yahoo dot com Assigned:
Status: Open Package: Filter related
PHP Version: Irrelevant OS: *
Private report: No CVE-ID: None
 [2011-05-19 05:27 UTC] 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 ;)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-27 17:01 UTC] design at gresak dot net
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)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 08:01:29 2024 UTC