php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42608 Example #660 (filter_input_array) is wrong
Submitted: 2007-09-10 11:04 UTC Modified: 2012-02-22 13:29 UTC
Votes:18
Avg. Score:4.3 ± 1.0
Reproduced:14 of 15 (93.3%)
Same Version:7 (50.0%)
Same OS:6 (42.9%)
From: phpbugs dot 20 dot zsh at spamgourmet dot com Assigned:
Status: Open Package: Filter related
PHP Version: 5.2.4 OS: Irrelevant
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-09-10 11:04 UTC] phpbugs dot 20 dot zsh at spamgourmet dot com
Description:
------------
The example will not output the array shown below the example code -- any undefined variable will cause filter_input_array() to return (so the output would be "NULL").

You'll notice I've classified this as a change request rather than a documentation problem, for the expected (and described ("Return Values")) behavior in example #660 makes WAY more sense.

Reproduce code:
---------------
http://www.php.net/filter_input_array


Patches

consistent_filter_input_array (last revision 2012-02-27 14:38 UTC) by datibbaw@php.net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-08 03:02 UTC] ChadFulton at gmail dot com
Although this is a very old bug, it seems to me that the poster is 
incorrect; I suspect the problem is that the poster attempted to set the 
$_POST array during runtime (e.g. $_POST = array( ... ); ), and 
filter_input_array does not allow runtime modification $_POST, $_GET, 
etc.
 [2011-02-21 20:59 UTC] jani@php.net
-Package: Feature/Change Request +Package: Filter related
 [2012-02-22 13:29 UTC] datibbaw@php.net
Fast forward to 2012, this is still wrong IMHO

Possible bugs:
1) documentation problem; the return value is defined as an array or false in case of failure - when the respective INPUT_XXX is not populated, it returns null; clearly not expected according to the documentation.
2) wrong behaviour in the code; if INPUT_XXX is not populated, I would expect the return value to be this: array_fill_keys(array_keys($definition), null)
 [2012-02-27 14:38 UTC] datibbaw@php.net
The following patch has been added/updated:

Patch Name: consistent_filter_input_array
Revision:   1330353526
URL:        https://bugs.php.net/patch-display.php?bug=42608&patch=consistent_filter_input_array&revision=1330353526
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Wed Apr 16 04:02:11 2014 UTC