Skip to content

array_filter ignores strict_types #12055

@divinity76

Description

@divinity76

Description

The following code:

<?php
declare(strict_types=1);

$arr = ["1"];
$filtered = array_filter($arr, function (int $i) {
    var_dump(["func_get_args" => func_get_args()]);
    return true;
});
var_dump($arr);

Resulted in this output:

array(1) {
  ["func_get_args"]=>
  array(1) {
    [0]=>
    int(1)
  }
}
array(1) {
  [0]=>
  string(1) "1"
}

But I expected this output instead:

Fatal error: Uncaught TypeError: {closure}(): Argument #1 ($i) must be of type int, string given in /in/Gf4Pq:5
Stack trace:
#0 [internal function]: {closure}('1')
#1 /in/Gf4Pq(5): array_filter(Array, Object(Closure))
#2 {main}
  thrown in /in/Gf4Pq on line 5

Process exited with code 255.

PHP Version

PHP 8.2.9

Operating System

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions