Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2178

Last hydrated element is passed by reference

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Can't Fix
    • Affects Version/s: 2.3
    • Fix Version/s: None
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None

      Description

      Test script:

      $em = $this->getDoctrine()->getEntityManager();
      $rows = $em->getRepository('FMECoreBundle:TheListGridRow')
      ->createQueryBuilder('row')
      ->getQuery()
      ->getArrayResult();
      var_dump($rows);

      Output:

      array(3) {
      [0]=>
      array(2)

      { ["id"]=> int(5) ["rank"]=> int(1) }

      [1]=>
      array(2)

      { ["id"]=> int(6) ["rank"]=> int(2) }

      [2]=>
      &array(2)

      { ["id"]=> int(7) ["rank"]=> int(3) }

      }

      As you can see the last element &array(2) is passed by reference and it broke my code. Can you check this please.

        Activity

        Menshinskiy Mikhail created issue -
        Hide
        Benjamin Eberlei added a comment -

        broke your code how? I am afraid this is required by the hydration algorithm and cannot be changed.

        Show
        Benjamin Eberlei added a comment - broke your code how? I am afraid this is required by the hydration algorithm and cannot be changed.
        Benjamin Eberlei made changes -
        Field Original Value New Value
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Can't Fix [ 7 ]
        Hide
        Menshinskiy Mikhail added a comment - - edited

        I think it's unexpected behaviour because NOT ALL but only the LAST element in
        array is passed by reference. Don't you think?

        I provided an example of issue below.

        I used the array $rows fetched above and passed it to the setParameter() like

        $this->getDoctrine()->getRepository('FMECoreBundle:Admin')
        ->createQueryBuilder('a')
        ->where('a.id IN (:ids)')
        ->setParameter('ids',$rows)
        ->getQuery()
        ->getResult();

        And now the $rows array contains the following:

        array(3) {
        [0]=>
        array(2)

        { ["id"]=> int(5) ["rank"]=> int(1) }

        [1]=>
        array(2)

        { ["id"]=> int(6) ["rank"]=> int(2) }

        [2]=>
        &int(7)
        }

        Of course I already solved this issue, but I have to remember all the time that the last element in hydrated array is passed by reference.

        I understand that it's a part of hydration algorithm, but I think it would be good to pay attention to this behaviour in the documentation to prevent a future problems.

        Thanks for your help.
        Regards.

        Show
        Menshinskiy Mikhail added a comment - - edited I think it's unexpected behaviour because NOT ALL but only the LAST element in array is passed by reference. Don't you think? I provided an example of issue below. I used the array $rows fetched above and passed it to the setParameter() like $this->getDoctrine()->getRepository('FMECoreBundle:Admin') ->createQueryBuilder('a') ->where('a.id IN (:ids)') ->setParameter('ids',$rows) ->getQuery() ->getResult(); And now the $rows array contains the following: array(3) { [0] => array(2) { ["id"]=> int(5) ["rank"]=> int(1) } [1] => array(2) { ["id"]=> int(6) ["rank"]=> int(2) } [2] => &int(7) } Of course I already solved this issue, but I have to remember all the time that the last element in hydrated array is passed by reference. I understand that it's a part of hydration algorithm, but I think it would be good to pay attention to this behaviour in the documentation to prevent a future problems. Thanks for your help. Regards.

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-2178, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

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

            Dates

            • Created:
              Updated:
              Resolved: