Skip to content

Using array_map() produces an unexpected result with array_search() #3789

@rvdsteege

Description

@rvdsteege

Bug report

Using array_map() produces an unexpected result with array_search():

Strict comparison using === between false and 0|1|2 will always evaluate to false.

However, array_search() can also return false (https://www.php.net/array_search):

Returns the key for needle if it is found in the array, FALSE otherwise.

For now, I've added /** @var array<int, string> $supported */ before the $supported declaration as an workaround.

Code snippet that reproduces the problem

✅ Works » https://phpstan.org/r/ae4801c3-0f97-45b4-a40b-171e51d7ebee

❌ Doesn't work » https://phpstan.org/r/7693163e-7db7-47fa-950d-baf59ec3f84c

Expected output

Expected no errors with the code snippet that reproduces the problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions