Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Check if two class memebers are null at the same time won't make non-null one of two when checking for the nullability of the other #9155

@DonCallisto

Description

@DonCallisto

Sorry for long title, I wasn't able to come up with a better one; hopefully it describe well what I'm trying to point out.
Basically if I have two nullable class members (let's call them foo and bar) which are two objects, and I check for both to be null (exiting the execution), when I check later for one of the twos (not important, let's say it's foo the candidate) to be null and call for a method on the other, which can't be null otherwise I would have exited from the execution, phpstan complains about the possible null.

If I do the same with method arguments (ie.: not class members) everything works as expected.
You can find below some examples

https://phpstan.org/r/5dc1149f-ccd6-48a8-bb29-b81899deaeb2
https://phpstan.org/r/c7ab95de-d3ff-496f-8f23-a6a6dd231a3c

Is this the expected behaviour?

Thank you in advance and cheers for the great tool!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions