Description
Description
Affected function: filter_input_array
After running all testsI had a coverage on this function like this, ... this is master at the moment:
So I wanted to add coverage on those missing lines. These lines are suppose to be hit when the input is missing and the FILTER_NULL_ON_FAILURE flag is passed. The as it is, will never reach the uncover lines; also, there are bugs in this code. Let analyze it a bit.
The function signature is:
filter_input_array(int $type, array|int $options = FILTER_DEFAULT, bool $add_empty = true): array|false|null
Now imagine we provide this test, trying to cover those missing lines:
--TEST--
filter_input_array: test FILTER_NULL_ON_FAILURE option does not affect general result on empty input
--EXTENSIONS--
filter
--FILE--
<?php
$args = [
"c" => [
"flags" => FILTER_NULL_ON_FAILURE,
]
];
var_dump(filter_input_array(INPUT_GET, $args, true));
?>
--EXPECT--
NULL
As I show in the image, the IF in violet will be true no matter what.
I also show in this image a lot of wrong things in the code.
So I could not cover the missing lines with tests, but instead I found the code needed to be fix.
Though about 2 possible solutions:
Solution 1: Change the function signature and add extra parameter
Because we cannot provide the flag for a missing input in the second parameter by function signature design, I tough about adding an extra parameter to the signature.
PR: #13803
Solution 2: Change the documentation and if input is missing, we just return NULL, period.
This is possible, as no code is able to get a FALSE return value if input is missing, so no code will be damage by such a solution.
PR: #13804
PHP Version
PHP 8.3
Operating System
Ubuntu 20.04