Skip to content

in_array check on an array with optional keys seems buggy #8864

Closed

Description

@VincentLanglet

Bug report

While working on phpstan/phpstan-src#2230, I discovered another issue with in_array type specifier.

Code snippet that reproduces the problem

https://phpstan.org/r/3e01e64c-0c75-4944-adb4-1f16c8c3418f

Expected output

I'm not sure what PHPStan would be able to do.
Narrowing the array array{0: 1, 1?: 2} with an in_array(2, check would be great. But we have to care about doing this like array{0: 1, 1?: 2, 2?: 2}

But at least the last error Expected type 2, actual: *NEVER* seems to be a bug to me.

Activity

  1. added this to the Easy fixes milestone on Feb 9, 2023
  2. deleted a comment from phpstan-bot on Jan 11, 2025
  3. phpstan-bot commented on Apr 1, 2026

    @phpstan-bot
    Contributor

    Closed via merging phpstan/phpstan-src#5365

  4. github-actions commented on May 3, 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.

  5. locked as resolved and limited conversation to collaborators on May 3, 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

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions