php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70263 filter_input_array 'add_empty' fails if query string absent
Submitted: 2015-08-13 22:24 UTC Modified: 2020-04-11 13:50 UTC
Votes:3
Avg. Score:4.7 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: mike dot whipps at littlevale dot co dot uk Assigned: cmb (profile)
Status: Not a bug Package: Filter related
PHP Version: 5.5.28 OS: Linux Fedora 20
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mike dot whipps at littlevale dot co dot uk
New email:
PHP Version: OS:

 

 [2015-08-13 22:24 UTC] mike dot whipps at littlevale dot co dot uk
Description:
------------
filter_input_array(INPUT_GET, $filters, true) does not add empty fields to the output array if the query string is absent. It does add them correctly if even one parameter appears.

Note that filter_var_array($_GET, $filters, true) does add the empty fields correctly.


Test script:
---------------
$getFilters = [
    'id'=>['filter'=>FILTER_VALIDATE_INT,
        'flags'=>FILTER_REQUIRE_SCALAR,
        'options'=>['min_range'=>1]
        ],
    'name'=>FILTER_UNSAFE_RAW
];

    echo '$_GET: <br>';
    var_dump($_GET);

    $req = filter_input_array(INPUT_GET, $getFilters, true);
    echo '<hr>$req:<br>';
    var_dump($req);

    echo '<hr>$reqGet<br>';
    $reqGet = filter_var_array($_GET, $getFilters, true);
    var_dump($reqGet);


Actual result:
--------------
Execute the above script with no query string gives this result:

$_GET:

array (size=0)
  empty

$req:

null

$reqGet

array (size=2)
  'id' => null
  'name' => null


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-01 13:22 UTC] vorbox+php at pp dot me
confirmed PHP7.4.0RC5 Windows 7 32.
 [2020-04-11 13:50 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-04-11 13:50 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

From the manual[1]:

| If the input array designated by type is not populated, the
| function returns NULL […]

[1] <https://www.php.net/manual/en/function.filter-input-array.php#refsect1-function.filter-input-array-returnvalues>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 16:01:28 2024 UTC