[php-src] Issue #13805: filter_input_array - bug and proposed fixes
| From: | juan-morales | Date: | Mon, 25 Mar 2024 20:10:18 +0000 |
| Subject: | [php-src] Issue #13805: filter_input_array - bug and proposed fixes | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-246648@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/13805
Author: juan-morales
### 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:
```php
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:
```php
--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