Skip to content

array_filter() does not consider that some elements might be dropped #7909

@jlherren

Description

@jlherren

Code snippet that reproduces the problem

function test(): void {
    $filenames = array_filter(['file1', 'file2'], 'file_exists');
    \PHPStan\dumpType($filenames);
}

https://phpstan.org/r/60cfb773-147f-422a-b2cb-dfe3ca211bc2

Actual output

Dumped type: array{'file1', 'file2'}

Expected output

The array may be empty, have one or two elements.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions