vimeo/psalm

Logic operations not parsed correctly in combination with class_exists

Open

#6,530 opened on Sep 24, 2021

View on GitHub
 (4 comments) (0 reactions) (0 assignees)PHP (668 forks)batch import
Help wantedbug

Repository metrics

Stars
 (5,369 stars)
PR merge metrics
 (Avg merge 3d 12h) (5 merged PRs in 30d)

Description

Not sure this issue has a wider impact, but this is how I found it.

Consider this snippet:

https://psalm.dev/r/6bc7fcec49

The issues reported for AnotherClass are false positives: it is impossible that the AnotherClass class is not defined due to the first if.

In fact, issues are correctly not reported for SomeClass.

If I split the logic operation in the first if and create two separate conditions everything works correctly:

https://psalm.dev/r/be71085536

So I think Psalm does not parse correctly logic operators with class_exists.

For additional context, see also:

https://psalm.dev/r/e8d3adb172

In there, the inner if would be executed only if both classes exist, so all the reported issues are false positives. And once again, with a single class everything works:

https://psalm.dev/r/0e43940c34

Contributor guide