🌐 US-Proxy
class="logged-out env-production page-responsive" style="word-wrap: break-word;" >
Skip to content

False Positive: Optional array key with type constraint remaines "mixed" (checkExplicitMixed) #6202

Description

@anbuc

Bug report

Only happens in lvl 9. The issue lies basically in this snippet:

if (isset($array['mightExist']) && !is_string($array['mightExist'])) {
    throw new Exception('Has to be string if set');
}

PHPStan still assumes that $array['mightExist'] is mixed, even though it can only be unset or string after that point. Interestingly, it does not complain if the key is used without null coalesce, even though it can still be unset

Code snippet that reproduces the problem

https://phpstan.org/r/4d0bc609-96f0-4eec-a029-5926d67f9370

Expected output

No error reported

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions