psalm icon indicating copy to clipboard operation
psalm copied to clipboard

SimpleXMLElement passes isset but can still be null

Open greg0ire opened this issue 1 year ago • 1 comments

https://psalm.dev/r/199041ce5b

I did not expect this PossiblyNullReference. If the value is set, then it must be different from null, right?

greg0ire avatar Feb 18 '24 15:02 greg0ire

I found these snippets:

https://psalm.dev/r/199041ce5b
<?php

function foo (SimpleXMLElement $xml): void 
{
    if (isset($xml['hi'])) {
        echo $xml['hi']->count();
    }
}
Psalm output (using commit c488d40):

ERROR: PossiblyNullReference - 6:26 - Cannot call method count on possibly null value

psalm-github-bot[bot] avatar Feb 18 '24 15:02 psalm-github-bot[bot]