Group as entity name is not parsed correctly in DQL #6491

Open
opened 2026-01-22 15:34:01 +01:00 by admin · 0 comments
Owner

Originally created by @BrtBnn on GitHub (Jun 18, 2020).

Bug Report

Q A
BC Break yes
Version 2.7.3

Summary

A syntax error is raised when executing a DQL statement.

Current behavior

A syntax error:line 0, col 15: Error: Expected Doctrine\ORM\Query\Lexer::T_ALIASED_NAME, got 'Group' is raised when executing a DQL statement: SELECT gr FROM Group gr

How to reproduce

Create an entity Group
Executing the following DQL statement: SELECT gr FROM Group gr raised the syntax error: line 0, col 15: Error: Expected Doctrine\ORM\Query\Lexer::T_ALIASED_NAME, got 'Group'

It seems that the Entity name Group is matched by the Lexer as a Lexer::T_GROUP, which is OK, but when parsing the from-clause in AbstractSchemaName() the Lexer::T_GROUP token is not matched as a identifier (although it should be), resulting in a syntax error when trying to match Lexer::T_GROUP as Lexer::T_ALIASED_NAME

Maybe the following fixes it already

    /**
     * AbstractSchemaName ::= fully_qualified_name | aliased_name | identifier
     *
     * @return string
     */
    public function AbstractSchemaName()
    {
        if ($this->lexer->isNextToken(Lexer::T_FULLY_QUALIFIED_NAME)) {
            $this->match(Lexer::T_FULLY_QUALIFIED_NAME);

            return $this->lexer->token['value'];
        }

        if ($this->lexer->isNextToken(Lexer::T_ALIASED_NAME)) {
            $this->match(Lexer::T_ALIASED_NAME);

            [$namespaceAlias, $simpleClassName] = explode(':', $this->lexer->token['value']);

            return $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName;
        }

        $this->match(Lexer::T_IDENTIFIER);

        return $this->lexer->token['value'];
    }

Expected behavior

In the DQL statement, Group is a valid identifier. So AbstractSchemaName() should parse it without raising syntax errors

Originally created by @BrtBnn on GitHub (Jun 18, 2020). ### Bug Report | Q | A |------------ | ------ | BC Break | yes | Version | 2.7.3 #### Summary A syntax error is raised when executing a DQL statement. #### Current behavior A syntax error:`line 0, col 15: Error: Expected Doctrine\ORM\Query\Lexer::T_ALIASED_NAME, got 'Group'` is raised when executing a DQL statement: `SELECT gr FROM Group gr` #### How to reproduce Create an entity `Group` Executing the following DQL statement: `SELECT gr FROM Group gr` raised the syntax error: `line 0, col 15: Error: Expected Doctrine\ORM\Query\Lexer::T_ALIASED_NAME, got 'Group'` It seems that the Entity name `Group` is matched by the Lexer as a `Lexer::T_GROUP`, which is OK, but when parsing the from-clause in [AbstractSchemaName()](https://github.com/doctrine/orm/blob/v2.7.3/lib/Doctrine/ORM/Query/Parser.php#L967) the `Lexer::T_GROUP` [token is not matched](https://github.com/doctrine/orm/blob/v2.7.3/lib/Doctrine/ORM/Query/Parser.php#L975) as a identifier (although it should be), resulting in a syntax error when trying to [match `Lexer::T_GROUP` as `Lexer::T_ALIASED_NAME`](https://github.com/doctrine/orm/blob/v2.7.3/lib/Doctrine/ORM/Query/Parser.php#L981) Maybe the following fixes it already ``` /** * AbstractSchemaName ::= fully_qualified_name | aliased_name | identifier * * @return string */ public function AbstractSchemaName() { if ($this->lexer->isNextToken(Lexer::T_FULLY_QUALIFIED_NAME)) { $this->match(Lexer::T_FULLY_QUALIFIED_NAME); return $this->lexer->token['value']; } if ($this->lexer->isNextToken(Lexer::T_ALIASED_NAME)) { $this->match(Lexer::T_ALIASED_NAME); [$namespaceAlias, $simpleClassName] = explode(':', $this->lexer->token['value']); return $this->em->getConfiguration()->getEntityNamespace($namespaceAlias) . '\\' . $simpleClassName; } $this->match(Lexer::T_IDENTIFIER); return $this->lexer->token['value']; } ``` #### Expected behavior In the DQL statement, Group is a valid identifier. So [AbstractSchemaName()](https://github.com/doctrine/orm/blob/v2.7.3/lib/Doctrine/ORM/Query/Parser.php#L967) should parse it without raising syntax errors
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#6491