Skip to content

Array value type is not narrowed when value itself is checked #7508

Open
phpstan/phpstan-src
#6386

Description

@BackEndTea

Bug report

Array value type is not narrowed when value itself is checked

Code snippet that reproduces the problem

https://phpstan.org/r/79e8e67c-7a7c-47bf-b7c7-87bdb1d7dcd1
https://phpstan.org/r/1a489aba-f2fc-4ac5-abb2-65b43379e0d0

Expected output

In the first example, there should be no error, in the second one, the dumped type should be int, not mixed.

Activity

  1. added this to the Dependent types milestone on Jun 22, 2022
  2. phpstan-bot commented on Sep 11, 2026

    @phpstan-bot
    Contributor

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

    @@ @@
    -No errors
    +9: Foreach value variable $value is never read.
    Full report
    Line Error
    9 Foreach value variable $value is never read.
  3. phpstan-bot commented on Sep 11, 2026

    @phpstan-bot
    Contributor

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

    @@ @@
    + 9: Foreach value variable $value is never read.
     14: Dumped type: int
    Full report
    Line Error
    9 Foreach value variable $value is never read.
    14 Dumped type: int
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