php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76366 References in sub-array for filtering breaks the filter
Submitted: 2018-05-22 14:03 UTC Modified: 2018-05-23 10:05 UTC
From: dirk dot gerigk at atraveo dot com Assigned:
Status: Closed Package: Filter related
PHP Version: 7.0Git-2018-05-22 (snap) OS: Ubuntu
Private report: No CVE-ID: None
 [2018-05-22 14:03 UTC] dirk dot gerigk at atraveo dot com
Description:
------------
When using an array for filter variables and one sub-array is (or has) an reference the filter will not filter. 
This happens in all versions PHP >= 7. In PHP 5.6 it works correct.
It takes me a long time to figure out, that the reference in the array produces the wrong behavior. If you var_dump $args before using it all seems fine.


Test script:
---------------
#array to filter
$data = ['foo' => 6];
#filter args
$args = ['foo'=> ['filter' => FILTER_VALIDATE_INT,'flags' => FILTER_FORCE_ARRAY]];
$args['foo']['options']=[];
#create reference
$options = &$args['foo']['options'];
#set options
$options['min_range']=1;
$options['max_range']=5;
#show the filter result
print_r(filter_var_array($data,$args));

Expected result:
----------------
Array ( [foo] => Array ( [0] => ) )

Actual result:
--------------
Array ( [foo] => Array ( [0] => 6 ) ) 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-05-23 10:05 UTC] cmb@php.net
-Status: Open +Status: Verified
 [2018-05-23 10:06 UTC] cmb@php.net
Confirmed: <https://3v4l.org/83gXR>
 [2018-07-07 10:08 UTC] nikic@php.net
Automatic comment on behalf of gao_zihang@hotmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=47fb17b108b401d8dbb5f1b94ec99ea0d020288a
Log: Fixed bug #76366 (references in sub-array for filtering breaks the filter)
 [2018-07-07 10:08 UTC] nikic@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 08:01:29 2024 UTC