Skip to content

in_array logic #9752

Closed
Closed

Description

@lugosium

Bug report

Hello,

An issue regarding how PHPStan deals with in_array.

Code snippet that reproduces the problem

https://phpstan.org/r/341e08ac-54fe-4f45-9586-703c1707060c

Expected output

PHPStan should not consider $car var as null.

Did PHPStan help you today? Did it make you happy in any way?

No response

Activity

  1. added this to the Dependent types milestone on Aug 14, 2023
  2. swissspidy commented on Aug 15, 2023

    @swissspidy

    Correct me if I'm wrong, but I don't see the issue here 🤔 If I call isOkOrNot('compact', null); this will invoke displayOk(null);. So this is a flaw in your logic, not PHPStan

  3. lugosium commented on Aug 15, 2023

    @lugosium
    Author

    if type compact or 4x4 and car is null you will enter the if, in elseif you car is necessarily an object, cannot be null.

  4. nuryagdym commented on Aug 29, 2023

    @nuryagdym

    in_array does not work for me also.
    Here is another example https://phpstan.org/r/4cbdb7cd-ab24-4a52-a816-b1e378cc11b4

  5. mad-briller commented on Aug 29, 2023

    @mad-briller
    Contributor

    @nuryagdym phpstan doesn't work well with loose equality semantics right now, pass a third arg of true to in_array and it's fine:
    https://phpstan.org/r/43426488-3c0a-4584-8b2a-a71ac97d85cc

  6. phpstan-bot commented on Aug 13, 2024

    @phpstan-bot
    Contributor

    @nuryagdym After the latest push in 1.12.x, PHPStan now reports different result with your code snippet:

    @@ @@
    -14: Parameter #1 $constant of method HelloWorld::foo() expects 1, 1|2 given.
    +No errors
  7. phpstan-bot commented on Sep 11, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#6381

  8. github-actions commented on Oct 13, 2026

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  9. locked as resolved and limited conversation to collaborators on Oct 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions