php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76734 Parameter type cannot be limited to scalar with FILTER_CALLBACK
Submitted: 2018-08-13 05:21 UTC Modified: 2018-08-14 06:21 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: 498936940 at qq dot com Assigned:
Status: Closed Package: Filter related
PHP Version: 7.2.8 OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: 498936940 at qq dot com
New email:
PHP Version: OS:

 

 [2018-08-13 05:21 UTC] 498936940 at qq dot com
Description:
------------
---
        var_dump(
            filter_input_array(
            INPUT_GET,
            [
                'id' => [
                    'filter' => FILTER_CALLBACK,
                    'options' => function($v){return $v;},
                    'flags'  => FILTER_REQUIRE_SCALAR,
                    ]
            ]
            )
        );
        exit();

/?id=2
array(1) {
  ["id"]=>
  string(1) "2"
}



/?id[]=3&id[]=4
array(1) {
  ["id"]=>
  array(2) {
    [0]=>
    string(1) "3"
    [1]=>
    string(1) "4"
  }
}
---
I must limit ID must be scalar, not array, filter cannot control!



Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-08-13 06:45 UTC] requinix@php.net
-Summary: Parameter type cannot be limited to scalar +Summary: Parameter type cannot be limited to scalar with FILTER_CALLBACK -Type: Bug +Type: Documentation Problem
 [2018-08-13 06:45 UTC] requinix@php.net
Flags are not used with FILTER_CALLBACK.

'id' => [
  'filter' => FILTER_CALLBACK,
  'options' => function($v){ return is_scalar($v) ? $v : null; },
]
 [2018-08-13 11:42 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=345461
Log: Fix #76734: Parameter type cannot be limited to scalar with FILTER_CALLBACK
 [2018-08-13 11:42 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2018-08-13 11:42 UTC] cmb@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.
 [2018-08-14 01:12 UTC] 498936940 at qq dot com
-Status: Closed +Status: Assigned -Type: Documentation Problem +Type: Bug
 [2018-08-14 01:12 UTC] 498936940 at qq dot com
···
        var_dump(
            filter_input_array(
            INPUT_GET,
            [
                'id' => [
                    'filter' => FILTER_CALLBACK,
                    'options' => function($v){ return is_scalar($v) ? $v : null; }
                    ]
            ]
            )
        );
        exit();

/?id=2
array(1) {
  ["id"]=>
  string(1) "2"
}



/?id[]=3&id[]=4
array(1) {
  ["id"]=>
  array(2) {
    [0]=>
    string(1) "3"
    [1]=>
    string(1) "4"
  }
}
···
I must limit ID must be scalar, not array, filter cannot control!
 [2018-08-14 02:01 UTC] 498936940 at qq dot com
-Status: Assigned +Status: Open
 [2018-08-14 02:01 UTC] 498936940 at qq dot com
Not just the Documentation Problem problem, but Bug still has problems.
 [2018-08-14 06:21 UTC] requinix@php.net
-Assigned To: cmb +Assigned To:
 [2018-08-14 06:21 UTC] requinix@php.net
Perhaps classifying this as a doc bug was premature. While the flags are deliberately not used, I see no way to use FILTER_CALLBACK and enforce a scalar or array: the callback is called on the non-array (leaf) values, so even with
  ?id[0][]=3&id[1][]=4
the callback only receives the values 3 and 4.

The obvious workaround is to apply two filters: one with filter_input_array and FILTER_REQUIRE_SCALAR, then another with filter_var_array and FILTER_CALLBACK.
 [2018-08-14 14:31 UTC] 498936940 at qq dot com
i'm feel no happy.
 [2020-02-07 06:05 UTC] phpdocbot@php.net
Automatic comment on behalf of cmb
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=a88a42497fb14cb2a3adc35d1e5962c4cec4275e
Log: Fix #76734: Parameter type cannot be limited to scalar with FILTER_CALLBACK
 [2020-02-07 06:05 UTC] phpdocbot@php.net
-Status: Open +Status: Closed
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 06:01:30 2024 UTC