Skip to content

PHPStan 2.1.32 make invalid || with instanceof invalid check #13804

@samsonasik

Description

@samsonasik

Bug report

After updating to PHPStan 2.1.32, or with instanceof check cause invalid result for:

class SomeClass implements Stringable
{
	#[Override]
    public function __toString(): string
    {
        return 'test';
    }
}

$data = rand(0, 1) ? 
	'test' 
	: new SomeClass;

if ((is_string($data) || $data instanceof SomeClass) && preg_match('/test/', (string) $data)) {

}

It shows

Instanceof between SomeClass and SomeClass will always evaluate to true.
Result of || is always true.

see https://phpstan.org/r/65540846-1bed-4ca6-80e8-038aba2ea92e

Code snippet that reproduces the problem

https://phpstan.org/r/65540846-1bed-4ca6-80e8-038aba2ea92e

Expected output

It should not show a phpstan notice.

see result https://3v4l.org/tK1i2

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

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions