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

Skip to content

Bug: False report Cannot call method getId() on A|null #9455

@jelovac

Description

@jelovac

Bug report

I am getting a false report that I cannot call a method on an object which is nullable. However, prior to calling the method I am ensuring that the object is not null.

		$hasA = $b->getA() !== null;

		if($hasA) {
			echo $b->getA()->getId();
		}

This works:

		if($b->getA() !== null) {
			echo $b->getA()->getId();
		}

Code snippet that reproduces the problem

https://phpstan.org/r/1f58efec-096f-45ca-a68a-4d28f221d242

Did PHPStan help you today? Did it make you happy in any way?

No response

Metadata

Metadata

Assignees

No one assigned

    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