Skip to content

strict type does not work array functions (array_map, array_walk, array_filter) using closures #17283

@proggeler

Description

@proggeler

Description

The following code:

<?php

declare(strict_types=1); // unfortunately strict types can not be declared on 3v4l.org

$array = [1, 1.2, '1.2.3'];

// var_dump(array_filter($array, function (string $value) { return is_string($value); })); // will not filter
// var_dump(array_map(fn (string $value) => $value, $array)); // all returned values are strings 

array_walk($array, fn (string &$value) => $value); 
var_dump($array);

Resulted in this output:

array(3) {
  [0]=>
  string(1) "1"
  [1]=>
  string(3) "1.2"
  [2]=>
  string(5) "1.2.3"
}

But I expected this output instead:

PHP Fatal error:  Uncaught TypeError: {closure}(): Argument #1 ($a) must be of type string, int given, .....

(as is thrown when call_user_func is used with a closure with a wrong argument type) 

PHP Version

PHP 8.3.6

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