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

False positive: isset on nested associative arrays #2718

Closed
Alban-io opened this issue Dec 10, 2019 · 2 comments
Closed

False positive: isset on nested associative arrays #2718

Alban-io opened this issue Dec 10, 2019 · 2 comments
Labels
Milestone

Comments

@Alban-io
Copy link

Bug report

+--------------------------------------------------------------+
| Line | test.php                                              |
+--------------------------------------------------------------+
| 23   | Unreachable statement - code above always terminates. |
+--------------------------------------------------------------+

Code snippet that reproduces the problem

➡️ https://phpstan.org/r/053b9b77-618e-4af2-8105-c2a572945565

<?php declare(strict_types = 1);

$fun = function (): array {
    return [
        ['group_id' => 'a', 'user_id' => 'id1'],
        ['group_id' => 'a', 'user_id' => 'id2'],
        ['group_id' => 'a', 'user_id' => 'id3'],
        ['group_id' => 'b', 'user_id' => 'id4'],
        ['group_id' => 'b', 'user_id' => 'id5'],
        ['group_id' => 'b', 'user_id' => 'id6'],
    ];
};

$orders = $fun();

$result = [];
foreach ($orders as $order) {
    // no error trigger with this statement
    // if (isset($result[$order['group_id']])) {
    if (isset($result[$order['group_id']]['users'])) {
        $result[$order['group_id']]['users'][] = $order['user_id'];
        continue;
    }

    $result[$order['group_id']] = [
        'users' => [
            $order['user_id'],
        ],
    ];
}

Expected output

 [OK] No errors 
@ondrejmirtes ondrejmirtes added this to the Easy fixes milestone Dec 30, 2019
@phpstan-bot
Copy link
Contributor

@Alban-io After the latest commit in dev-master, PHPStan now reports different result with your code snippet:

@@ @@
-23: Unreachable statement - code above always terminates.
+No errors

@github-actions
Copy link

github-actions bot commented Mar 4, 2022

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 Mar 4, 2022
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

3 participants