Skip to content

in_array with array of literals is always true when it is possible to contain the checked value. #5668

@BackEndTea

Description

@BackEndTea

Bug report

When doing an in_array check on an array with string literals, it is always true if the checked string matches one of the literals.

In both has1, has2 and has3 the type is not correct, as the array may be empty, or contain another value.

Code snippet that reproduces the problem

https://phpstan.org/r/2d2fb268-4ecd-4255-b8a2-312a0c7cbfaf

Expected output

Dumped types in order:

  • bool
  • bool
  • bool
  • true (this one is correct already)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions