Skip to content

\stdClass not treated as an object with generics #2955

Open

Description

@ramonacat

Bug report

If there's a @template T of object, then PHPStan complains that \stdClass is not an object.

Code snippet that reproduces the problem

https://phpstan.org/r/b871a595-152c-47cc-a1a3-c93639ec791b

Expected output

No errors. \stdClass is a subtype of object

Activity

  1. added this to the Generics milestone on Feb 6, 2020
  2. phpstan-bot commented on Apr 6, 2023

    @phpstan-bot
    Contributor

    @Agares After the latest push in 1.10.x, PHPStan now reports different result with your code snippet:

    @@ @@
    -10: Function test() should return T of object but returns stdClass.
    +10: Function test() should return T of object but returns object{}&stdClass.
    Full report
    Line Error
    10 Function test() should return T of object but returns object{}&stdClass.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions