Skip to content

class-string vs literal-string in QueryBuilder #332

@mhujer

Description

@mhujer

With the recent addition of literal-types to QueryBuilder (#327), I'm getting warnings when passing class-string there: Parameter #1 $from of method Doctrine\ORM\QueryBuilder::from() expects literal-string, class-string given

This is the simplified example to reproduce the issue:

    /**
     * @param class-string $className
     */
    public function getSortable(
        string $className,
    ): ?Sortable
    {
        return $this
            ->entityManager
            ->createQueryBuilder()
            ->select('sortable')
            ->from($className, 'sortable')
            ->getQuery()
            ->getOneOrNullResult();
    }

What is do you think is the correct way to handle this? To me it seems that class-string is more specific type than the literal-string.

cc @VincentLanglet

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