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

Skip to content

Moving (instanceof A || instanceof B) from if statement causes error #9519

@belisoful

Description

@belisoful

Bug report

This works

if (($obj instanceof ClassA) || ($obj instanceof ClassB)) {
	$obj->sayHello();
}

and this does not:

$isHelloWorld = $obj instanceof ClassA;
$isHelloWorld2 = $obj instanceof ClassB;

if ($isHelloWorld || $isHelloWorld2) {
	$obj->sayHello(); // <- Cannot call method sayHello() on mixed.
}

The variable types are not being picked up when passed through a variable like this.

Code snippet that reproduces the problem

https://phpstan.org/r/19a7c6f9-38b1-4557-9348-d702baa1de9b

Expected output

No error

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