[php-src] Issue #23488: PHP 8.6 | array_filter() mode validation is non-strict + same for array_change_key_case() $case
| From: | jrfnl | Date: | Fri, 28 Aug 2026 23:15:58 +0000 |
| Subject: | [php-src] Issue #23488: PHP 8.6 | array_filter() mode validation is non-strict + same for array_change_key_case() $case | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-252680@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/23488
Author: jrfnl
### Description
This is related to the following PRs which have been merged for PHP 8.6:
* #15647
* #15883
/cc @Girgias, @jorgsowa
The following code:
```php
<?php
$arr = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4];
var_dump(array_filter($arr, function($v) {
return $v == 4;
}, false));
$arr = ['a' => 1];
var_dump(array_change_key_case($arr, '0'));
```
Resulted in this output:
```
array(1) {
["d"]=>
int(4)
}
array(1) {
["a"]=>
int(1)
}
```
But I expected this output instead:
```
array_filter(): Argument #3 ($mode) must be of type int, boolean given
array_change_key_case(): Argument #2 ($case) must be of type int, string given
```
## Reasoning
Since PHP 8.0, passing a parameter of an incorrect type to a PHP native function generally results
in a
TypeError.
This is also the case for the above two functions, **_but only if the value with an invalid type
does not (cleanly) juggle to one of the valid values_**...
In other words, passing boolean false or true, text strings
'0', '1' or '2' or any float
which would juggle to integer 0, 1 or 2 will still be
accepted and not result in either a TypeError or a ValueError.
To me, this is surprising. I would have expected those values to throw a TypeError,
just like a non-integer which doesn't cleanly juggle to one of the valid values does.
Detailed 3v4ls:
* array_filter(): https://3v4l.org/aGq6E/rfc#vgit.master
* array_change_key_case(): https://3v4l.org/k8YmZ/rfc#vgit.master
### PHP Version
```plain
Git master per 2026-08-29
```
### Operating System
_No response_