Skip to content

Yield + outside property change = false positive #8337

@LastDragon-ru

Description

@LastDragon-ru

Bug report

If you do something like you will get "Strict comparison using !== between 1 and 1 will always evaluate to false." that is not true because $this->offset can be changed while yield.

foreach ([1, 2, 3] as $item) {
    $this->offset = 1;

    yield $index => $item;

    if ($this->offset !== 1) {
        throw new Exception('bug');
    }

    $index += $this->offset;
}

Code snippet that reproduces the problem

https://phpstan.org/r/4068130e-8b2e-4849-b751-c56b69dcf3bb
https://3v4l.org/d8R5J

Expected output

No error

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions