Skip to content

self::class in entity is interpreted in wrong context #512

Open
@jlherren

Description

@jlherren

With this entity:

#[Entity]
class Person {
    #[Id]
    #[Column(type: "integer")]
    public int $id;

    public static function getQb(EntityManager $em): QueryBuilder {
        return $em->createQueryBuilder()
                  ->select('p')
                  ->from(self::class, 'p');
    }
}

And this code:

class Test {
    public static function test(EntityManager $em): void {
        Person::getQb($em)->getQuery()->getResult();
    }
}

I get the following error:

 -- --------------------------------------------------------------------------------------------------------------------
     Error
 -- --------------------------------------------------------------------------------------------------------------------
     Internal error: Internal error: Class "App\Test" is not a valid entity or mapped super class. while analysing file
     C:\Projekte\TestProjects\PhpstanDoctrine\src\Test.php
     Run PHPStan with -v option and post the stack trace to:
     https://github.com/phpstan/phpstan/issues/new?template=Bug_report.yaml
     Child process error (exit code 1):
 -- --------------------------------------------------------------------------------------------------------------------

If I replace self::class with Person::class, it works as expected. It seems that self is being understood to be Test, when in fact it refers to Person. I can provide a fuller reproduction example if desired. This seems to have gone broken in a recent release.

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