BC: Expected Doctrine\ORM\Query\Lexer::T_ALIASED_NAME, got 'Member' #5991

Closed
opened 2026-01-22 15:24:13 +01:00 by admin · 9 comments
Owner

Originally created by @caugner on GitHub (Jun 17, 2018).

Originally assigned to: @lcobucci on GitHub.

BC Break Report

Q A
BC Break yes
Version 2.6.1

Summary

I have an entity Member (with a field id), and determine the maximum id as follows:

<?php
$em->getRepository('Member')
   ->createQueryBuilder()
   ->select('MAX(m.id)')
   ->getQuery()
   ->getSingleScalarResult();

Previous behavior

It used to return the highest id (in 2.5.x).

Current behavior

This throws a QueryException now (in 2.6.1):

[Syntax Error] line 0, col 22: Error: Expected Doctrine\ORM\Query\Lexer::T_ALIASED_NAME, got 'Member'

#0 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(452): Doctrine\ORM\Query\QueryException::syntaxError('line 0, col 22:...', Object(Doctrine\ORM\Query\QueryException))
#1 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(309): Doctrine\ORM\Query\Parser->syntaxError('Doctrine\\ORM\\Qu...')
#2 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(967): Doctrine\ORM\Query\Parser->match(100)
#3 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1726): Doctrine\ORM\Query\Parser->AbstractSchemaName()
#4 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1578): Doctrine\ORM\Query\Parser->RangeVariableDeclaration()
#5 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1313): Doctrine\ORM\Query\Parser->IdentificationVariableDeclaration()
#6 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(874): Doctrine\ORM\Query\Parser->FromClause()
#7 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(843): Doctrine\ORM\Query\Parser->SelectStatement()
#8 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(259): Doctrine\ORM\Query\Parser->QueryLanguage()
#9 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(355): Doctrine\ORM\Query\Parser->getAST()
#10 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query.php(283): Doctrine\ORM\Query\Parser->parse()
#11 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query.php(295): Doctrine\ORM\Query->_parse()
#12 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(957): Doctrine\ORM\Query->_doExecute()
#13 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(912): Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(NULL, 4)
#14 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(793): Doctrine\ORM\AbstractQuery->execute(NULL, 4)
#15 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(821): Doctrine\ORM\AbstractQuery->getSingleResult(4)
#16 /path/to/app/public/test.php(11): Doctrine\ORM\AbstractQuery->getSingleScalarResult()
#17 {main}

How to reproduce

See code snippet above.

Originally created by @caugner on GitHub (Jun 17, 2018). Originally assigned to: @lcobucci on GitHub. ### BC Break Report | Q | A |------------ | ------ | BC Break | yes | Version | 2.6.1 #### Summary I have an entity `Member` (with a field `id`), and determine the maximum `id` as follows: ```php <?php $em->getRepository('Member') ->createQueryBuilder() ->select('MAX(m.id)') ->getQuery() ->getSingleScalarResult(); ``` #### Previous behavior It used to return the highest `id` (in 2.5.x). #### Current behavior This throws a `QueryException` now (in 2.6.1): > [Syntax Error] line 0, col 22: Error: Expected Doctrine\ORM\Query\Lexer::T_ALIASED_NAME, got 'Member' ``` #0 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(452): Doctrine\ORM\Query\QueryException::syntaxError('line 0, col 22:...', Object(Doctrine\ORM\Query\QueryException)) #1 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(309): Doctrine\ORM\Query\Parser->syntaxError('Doctrine\\ORM\\Qu...') #2 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(967): Doctrine\ORM\Query\Parser->match(100) #3 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1726): Doctrine\ORM\Query\Parser->AbstractSchemaName() #4 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1578): Doctrine\ORM\Query\Parser->RangeVariableDeclaration() #5 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(1313): Doctrine\ORM\Query\Parser->IdentificationVariableDeclaration() #6 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(874): Doctrine\ORM\Query\Parser->FromClause() #7 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(843): Doctrine\ORM\Query\Parser->SelectStatement() #8 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(259): Doctrine\ORM\Query\Parser->QueryLanguage() #9 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php(355): Doctrine\ORM\Query\Parser->getAST() #10 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query.php(283): Doctrine\ORM\Query\Parser->parse() #11 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/Query.php(295): Doctrine\ORM\Query->_parse() #12 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(957): Doctrine\ORM\Query->_doExecute() #13 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(912): Doctrine\ORM\AbstractQuery->executeIgnoreQueryCache(NULL, 4) #14 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(793): Doctrine\ORM\AbstractQuery->execute(NULL, 4) #15 /path/to/app/vendor/doctrine/orm/lib/Doctrine/ORM/AbstractQuery.php(821): Doctrine\ORM\AbstractQuery->getSingleResult(4) #16 /path/to/app/public/test.php(11): Doctrine\ORM\AbstractQuery->getSingleScalarResult() #17 {main} ``` #### How to reproduce See code snippet above.
admin added the BugInvalid labels 2026-01-22 15:24:13 +01:00
admin closed this issue 2026-01-22 15:24:13 +01:00
Author
Owner

@Warxcell commented on GitHub (Aug 11, 2018):

Can you try following instead:

<?php $em->getRepository('Member') ->createQueryBuilder('m') ->select('MAX(m.id)') ->getQuery() ->getSingleScalarResult();

@Warxcell commented on GitHub (Aug 11, 2018): Can you try following instead: `<?php $em->getRepository('Member') ->createQueryBuilder('m') ->select('MAX(m.id)') ->getQuery() ->getSingleScalarResult(); `
Author
Owner

@caugner commented on GitHub (Aug 12, 2018):

@Warxcell Thanks for your response. I can't spot a difference between your snippet and mine, could you elaborate on that?

@caugner commented on GitHub (Aug 12, 2018): @Warxcell Thanks for your response. I can't spot a difference between your snippet and mine, could you elaborate on that?
Author
Owner

@Warxcell commented on GitHub (Aug 12, 2018):

@caugner Opps. Sorry, my wrong. I edited my response.

@Warxcell commented on GitHub (Aug 12, 2018): @caugner Opps. Sorry, my wrong. I edited my response.
Author
Owner

@lcobucci commented on GitHub (Aug 12, 2018):

@caugner as pointed out by @Warxcell, the method EntityRepository#createQueryBuilder() requires an argument - which is not provided by your snippet. That argument is mandatory for a very long time.

Can you double check on your code if you're really not providing that argument? That's also supposed to raise a fatal error in PHP 7.1+ (it was a warning before).

@lcobucci commented on GitHub (Aug 12, 2018): @caugner as pointed out by @Warxcell, the method `EntityRepository#createQueryBuilder()` requires an argument - which is not provided by your snippet. That argument is mandatory for a very long time. Can you double check on your code if you're **really** not providing that argument? That's also supposed to raise a fatal error in PHP 7.1+ (it was a warning before).
Author
Owner

@caugner commented on GitHub (Aug 12, 2018):

@lcobucci I was on PHP 7.1 when I updated from 2.5.1 to 2.6.1, and I'm pretty sure it neither raised a fatal error nor a warning (I have PHP error reporting via email that includes warnings); hence the BC Break Report.

As this issue has served its purpose though, I'm closing it now.

@Warxcell @lcobucci Thank you for explaining the reason for this exception.

@caugner commented on GitHub (Aug 12, 2018): @lcobucci I was on PHP 7.1 when I updated from 2.5.1 to 2.6.1, and I'm pretty sure it neither raised a fatal error nor a warning (I have PHP error reporting via email that includes warnings); hence the BC Break Report. As this issue has served its purpose though, I'm closing it now. @Warxcell @lcobucci Thank you for explaining the reason for this exception.
Author
Owner

@lcobucci commented on GitHub (Aug 12, 2018):

@caugner glad it helped 👍

The fact that nothing was reported is quite disturbing and I'd recommend you to review your configuration - you can check PHP's behaviour here: https://3v4l.org/7rVFR.

@lcobucci commented on GitHub (Aug 12, 2018): @caugner glad it helped :+1: The fact that nothing was reported is quite disturbing and I'd recommend you to review your configuration - you can check PHP's behaviour here: https://3v4l.org/7rVFR.
Author
Owner

@Limado commented on GitHub (May 31, 2020):

I'm having a similar issue.

My code:
$groups = $em->getRepository('Group')
->createQueryBuilder('g')
->where('g.users LIKE :myUserId')
->setParameter('myUserId', '%' . $user->getId() . '%')
->getQuery()
->getResult();


the error i'm getting :

Doctrine\ORM\Query\QueryException: [Syntax Error] line 0, col 14: Error: Expected Doctrine\ORM\Query\Lexer::T_ALIASED_NAME, got 'Group'


Tried 3 diferent way of building DQL, always getting same error.

_dql: "SELECT g FROM Group g WHERE g.users LIKE :myUserId"

@Limado commented on GitHub (May 31, 2020): I'm having a similar issue. My code: $groups = $em->getRepository('Group') ->createQueryBuilder('g') ->where('g.users LIKE :myUserId') ->setParameter('myUserId', '%' . $user->getId() . '%') ->getQuery() ->getResult(); **************************************************************************************************************** the error i'm getting : Doctrine\ORM\Query\QueryException: [Syntax Error] line 0, col 14: Error: Expected Doctrine\ORM\Query\Lexer::T_ALIASED_NAME, got 'Group' **************************************************************************************************************** Tried 3 diferent way of building DQL, always getting same error. _dql: "SELECT g FROM Group g WHERE g.users LIKE :myUserId"
Author
Owner

@Warxcell commented on GitHub (May 31, 2020):

@Limado Don't use Group. It's reserved word.

@Warxcell commented on GitHub (May 31, 2020): @Limado Don't use Group. It's reserved word.
Author
Owner

@yassineMessaoud9 commented on GitHub (Apr 10, 2022):

i the same error:
My code :
`
public function updateU($password,$email): ?Utilisateur
{
$qb = $this->getEntityManager()
->createQueryBuilder()
->update(Utilisateur::class,'u');
$qb
->where($qb->expr()->eq('u.motpasse',':password'))
->andWhere($qb->expr()->eq('u.email',':email'))
->setParameter('password',$password)
->setParameter('email',$email);

return $qb->getQuery()->getResult();  

}
`

Error:
[Syntax Error] line 0, col 32: Error: Expected Doctrine\ORM\Query\Lexer::T_SET, got 'WHERE'

@yassineMessaoud9 commented on GitHub (Apr 10, 2022): i the same error: My code : ` public function updateU($password,$email): ?Utilisateur { $qb = $this->getEntityManager() ->createQueryBuilder() ->update(Utilisateur::class,'u'); $qb ->where($qb->expr()->eq('u.motpasse',':password')) ->andWhere($qb->expr()->eq('u.email',':email')) ->setParameter('password',$password) ->setParameter('email',$email); return $qb->getQuery()->getResult(); } ` -------------------------------------------------- Error: `[Syntax Error] line 0, col 32: Error: Expected Doctrine\ORM\Query\Lexer::T_SET, got 'WHERE' `
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#5991