DQL does not work when setlocale(LC_ALL, 'tr_TR'); was called before #4945

Open
opened 2026-01-22 14:53:38 +01:00 by admin · 0 comments
Owner

Originally created by @AnnaDamm on GitHub (Dec 18, 2015).

When you set the locale with setlocale for specific languages before using DQL, the Lexer splits the tokens wrong:

(inside a ProductGroupMemberRepository EntityRepository class)

    setlocale(LC_ALL, 'tr_TR');

    $qb   = $this->createQueryBuilder('m');
        $expr = $qb->expr();

        $qb->select('p')
            ->innerJoin('Entity\Product', 'p', 'WITH', 'm.productId = p.id')
            ->where($expr->eq("m.groupId", ":groupId"))
            ->setParameter(":groupId", $groupId);
    return $qb->getQuery()->getResult();

It breaks with the error message: Error: Expected end of string, got 'I'
After some debugging, I found that preg_split apparently works differently on tr_TR. it splits on different characters:

array(36) {
  [0]=>
  array(2) {
    [0]=>
    string(6) "SELECT"
    [1]=>
    int(0)
  }
  [1]=>
  array(2) {
    [0]=>
    string(1) "p"
    [1]=>
    int(7)
  }
  [2]=>
  array(2) {
    [0]=>
    string(4) "FROM"
    [1]=>
    int(9)
  }
  [3]=>
  array(2) {
    [0]=>
    string(40) "Entity\ProductGroupMember"
    [1]=>
    int(14)
  }
  [4]=>
  array(2) {
    [0]=>
    string(1) "m"
    [1]=>
    int(55)
  }
  [5]=>
  array(2) {
    [0]=>
    string(1) "I"
    [1]=>
    int(57)
  }
  [6]=>
  array(2) {
    [0]=>
    string(4) "NNER"
    [1]=>
    int(58)
  }
  [7]=>
  array(2) {
    [0]=>
    string(2) "JO"
    [1]=>
    int(63)
  }
  [8]=>
  array(2) {
    [0]=>
    string(1) "I"
    [1]=>
    int(65)
  }
  [9]=>
  array(2) {
    [0]=>
    string(1) "N"
    [1]=>
    int(66)
  },
...

If I use setlocale with LC_NUMERIC or comment the line out, or use other languages, everything works fine. Even though the regex and DQL are exactly the same thing.

Originally created by @AnnaDamm on GitHub (Dec 18, 2015). When you set the locale with `setlocale` for specific languages before using DQL, the Lexer splits the tokens wrong: (inside a ProductGroupMemberRepository EntityRepository class) ``` php setlocale(LC_ALL, 'tr_TR'); $qb = $this->createQueryBuilder('m'); $expr = $qb->expr(); $qb->select('p') ->innerJoin('Entity\Product', 'p', 'WITH', 'm.productId = p.id') ->where($expr->eq("m.groupId", ":groupId")) ->setParameter(":groupId", $groupId); return $qb->getQuery()->getResult(); ``` It breaks with the error message: `Error: Expected end of string, got 'I'` After some debugging, I found that preg_split apparently works differently on tr_TR. it splits on different characters: ``` array(36) { [0]=> array(2) { [0]=> string(6) "SELECT" [1]=> int(0) } [1]=> array(2) { [0]=> string(1) "p" [1]=> int(7) } [2]=> array(2) { [0]=> string(4) "FROM" [1]=> int(9) } [3]=> array(2) { [0]=> string(40) "Entity\ProductGroupMember" [1]=> int(14) } [4]=> array(2) { [0]=> string(1) "m" [1]=> int(55) } [5]=> array(2) { [0]=> string(1) "I" [1]=> int(57) } [6]=> array(2) { [0]=> string(4) "NNER" [1]=> int(58) } [7]=> array(2) { [0]=> string(2) "JO" [1]=> int(63) } [8]=> array(2) { [0]=> string(1) "I" [1]=> int(65) } [9]=> array(2) { [0]=> string(1) "N" [1]=> int(66) }, ... ``` If I use `setlocale` with `LC_NUMERIC` or comment the line out, or use other languages, everything works fine. Even though the regex and DQL are exactly the same thing.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4945