Skip to content

Strict comparison using === between class-string<XXX> and 'YYY' will always evaluate to false. #3633

@jacekkarczmarczyk

Description

@jacekkarczmarczyk

Bug report

phpstan 0.12.33

Following code throws an error

Code snippet that reproduces the problem

https://phpstan.org/r/079841f1-1961-44a4-acfa-c8a308fea2fc

<?php declare(strict_types = 1);

trait Foo {
	public function test(): void {
		if (get_class($this) === HelloWorld::class) {
			echo "OK";
		}
		if (get_class($this) === OtherClass::class) {
			echo "OK";
		}
	}
}

class HelloWorld {
	use Foo;
	
	public function bar(): void {
		$this->test();
	}
}

class OtherClass {
	use Foo;
	
	public function bar(): void {
		$this->test();
	}
}

Expected output

No error

Additional notes

Might be related to #3632

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions