Skip to content

ext/filter: filter_var_array with FILTER_VALIDATE_INT|FILTER_NULL_ON_FAILURE for an entry flag does not validate. #16993

Open
@Girgias

Description

@Girgias

Description

The following code:

<?php
$data = [
    'product_id' => '42',
    'component1'  => '10.36',
    'component2'  => '10.36',
];

$filters = [
    'product_id'   => FILTER_VALIDATE_INT,
    'component1'    => FILTER_VALIDATE_INT,
    'component2'    => FILTER_VALIDATE_INT|FILTER_NULL_ON_FAILURE,
    'doesnotexist1' => FILTER_VALIDATE_INT,
    'doesnotexist2' => FILTER_VALIDATE_INT|FILTER_NULL_ON_FAILURE,
];

var_dump(filter_var_array($data, $filters));

Resulted in this output:

array(5) {
  ["product_id"]=>
  int(42)
  ["component1"]=>
  bool(false)
  ["component2"]=>
  string(5) "10.36"
  ["doesnotexist1"]=>
  NULL
  ["doesnotexist2"]=>
  NULL
}

But I expected this output instead:

array(5) {
  ["product_id"]=>
  int(42)
  ["component1"]=>
  bool(false)
  ["component2"]=>
  NULL
  ["doesnotexist1"]=>
  NULL
  ["doesnotexist2"]=>
  NULL
}

PHP Version

PHP 5.4.0 to master

Operating System

No response

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions