Skip to content

An object using a trait with the __toString() method is not considered as Stringable #13469

@tg666

Description

@tg666

Bug report

As mentioned in the issue title.
PHPStan does not consider a class instance to be Stringable if the __toString() method is implemented in a trait that the class uses.
The condition $object instanceof \Stringable passes without any problems, but PHPStan reports:

Instanceof between XXX and Stringable will always evaluate to false.

Code snippet that reproduces the problem

https://phpstan.org/r/6621497c-dab7-4f5b-acfe-be260fac6546

Expected output

The object should be considered as Stringable.

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

Ofc! currently it helps me detect errors during refactoring.

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