Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ArrayDimFetch probably null on Iterator fetch detected as non null #9784

Closed
samsonasik opened this issue Aug 21, 2023 · 2 comments
Closed

ArrayDimFetch probably null on Iterator fetch detected as non null #9784

samsonasik opened this issue Aug 21, 2023 · 2 comments
Labels

Comments

@samsonasik
Copy link

Bug report

For example, I have the following code:

final class DemoFile
{
    private function complementArticleData(Iterator $articles): void
    {
        $result = [
            'artikel' => $articles,
            'farben' => null,
            'artikel_ids' => [],
        ];

        // collect article ids
        foreach ($result['artikel'] as $article) {
            $result['artikel_ids'][] = 1;
        }

        if ($result['artikel_ids'] !== []) {
            $result['farben'] = new stdClass();
        }

        // $result['farben'] might be also null
		\PHPStan\dumpType($result['farben']);
        if ($result['farben'] instanceof stdClass) {
            echo '123';
        }
    }
}

Above, \PHPStan\dumpType($result['farben']); should be null|stdClass, but detected only as stdClass.

Code snippet that reproduces the problem

https://phpstan.org/r/05fd1758-7df0-4307-b419-dc29bd867ae4

Expected output

It should output null|stdClass as type.

Array vs Iterator result:

Array: working OK https://phpstan.org/r/dcded1e7-0941-4d6b-9451-c33face0ff89
Iterator: NOT working https://phpstan.org/r/05fd1758-7df0-4307-b419-dc29bd867ae4

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

No response

@ondrejmirtes
Copy link
Member

Fixed: phpstan/phpstan-src@853a1e6

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants