Skip to content

Call to method foo() on an unknown class FooBar when FooBar is a trait #7720

Description

@kylekatarnls

Bug report

Code snippet that reproduces the problem

<?php declare(strict_types = 1);

trait FooBar
{
	public function foo(): string
	{
		return 'abc';
	}
}

class HelloWorld
{
	public function sayHello(mixed $value): void
	{
		if ($value instanceof FooBar) {
			echo $value->foo();
		}
	}
}

https://phpstan.org/r/21864fe8-ba76-4945-b9fc-9dc27e286ca1

Expected output

I expect no error for the code above.

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

This snippet system with try is still very cool to be sure in a blink if current version has the same output.

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