[php-src] Issue #16029: Inconsistent behavior of `filter_var()` with `FILTER_REQUIRE_ARRAY` and `default` option for non-array inputs
| From: | rubenferreira97 | Date: | Tue, 24 Sep 2024 17:14:01 +0000 |
| Subject: | [php-src] Issue #16029: Inconsistent behavior of `filter_var()` with `FILTER_REQUIRE_ARRAY` and `default` option for non-array inputs | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247882@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/16029
Author: rubenferreira97
### Description
The following code:
```php
<?php
var_dump(filter_var("a", FILTER_VALIDATE_INT, ['flags' =>
FILTER_REQUIRE_ARRAY, 'options' => ['default' => 'Failed']]));
var_dump(filter_var([1], FILTER_VALIDATE_INT, ['flags' => FILTER_REQUIRE_ARRAY,
'options' => ['default' => 'Failed']]));
var_dump(filter_var(["a"], FILTER_VALIDATE_INT, ['flags' =>
FILTER_REQUIRE_ARRAY, 'options' => ['default' => 'Failed']]));
var_dump(filter_var("a", FILTER_VALIDATE_INT, ['options' =>
['default' => 'Failed']]));
```
Resulted in this output:
```
bool(false)
array(1) {[0]=> int(1)}
array(1) {[0]=> string(6) "Failed"}
string(6) "Failed"
```
But I expected this output instead:
```
array(1) {[0]=> string(6) "Failed"}
array(1) {[0]=> int(1)}
array(1) {[0]=> string(6) "Failed"}
string(6) "Failed"
```
Since the documentation says:
>
default, value to return if the filter fails
I was expecting to get at least some form of Failed.
### PHP Version
PHP 8.3
### Operating System
Windows 11