Skip to content

Asserting isset twice on maybe-nullable offsets of same array results in error #1924

@muglug

Description

@muglug
function getMaybeArray() : ?array {
    if (rand(0, 1)) { return [1, 2, 3]; }
    return null;
}

$arr = [
    'a' => getMaybeArray(),
    'b' => getMaybeArray(),
];
  
if (isset($arr['a']) && isset($arr['b'])) {}

Expected: no issue
Actual: Result of && is always true.

https://phpstan.org/r/a8dfa0d7-2df4-4af2-a3fb-6e138c34b36f

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions