Skip to content

"Variable $i might not be defined." in for loop using comma operator (binary search) #3858

@gnutix

Description

@gnutix

Bug report

While implementing a binary search, we used a comma operator within a for loop and use the $i variable outside the loop too, and it is in practice always defined.

Code snippet that reproduces the problem

https://phpstan.org/r/85c66c6f-a6d4-4084-8815-07d3f46b099d
https://3v4l.org/LVt1P

Expected output

No errors

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions