Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-3018

DQL “NEW” Operator and Literal type "String"

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.4, Git Master, 2.5
    • Fix Version/s: 2.5, 2.4.3
    • Component/s: DQL
    • Security Level: All
    • Labels:

      Description

      Hello all,

      When i use the DQL operator "new" to build data transfert object with string literal expression as field in object constructor, the call to Query::getResult thrown an exception.

      Condition :
      The string literal expression must be the first parameter of the constructor.

      Following DQL :

      $query = $em->createQuery('SELECT NEW CustomerDTO('some scalar string', c.name, c.email) FROM Customer c');
      
      $users = $query->getResult();
      

      Thrown exception :

      ContextErrorException: Notice: Undefined variable: fieldType in doctrine/orm/lib/Doctrine/ORM/Query/SqlWalker.php line 1527

      That happens because in SqlWalker::walkNewObject on the AST\Literal switch case. There is no case for AST\Literal::STRING, so $fieldType isn't defined.

      I have also noted if the scalar string isn't the first parameter, $fieldType take the type of previous foreach element.

        Activity

        Hide
        Benjamin Eberlei added a comment -

        Fixed and merged into 2.4 release branch

        Show
        Benjamin Eberlei added a comment - Fixed and merged into 2.4 release branch

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            harleaux
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: