[DDC-2178] Last hydrated element is passed by reference Created: 29/Nov/12  Updated: 16/Dec/12  Resolved: 16/Dec/12

Status: Resolved
Project: Doctrine 2 - ORM
Component/s: ORM
Affects Version/s: 2.3
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Menshinskiy Mikhail Assignee: Benjamin Eberlei
Resolution: Can't Fix Votes: 0
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.



 Comments   
Comment by Benjamin Eberlei [ 16/Dec/12 ]

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

Comment by Menshinskiy Mikhail [ 16/Dec/12 ]

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.

Generated at Sun Sep 21 00:04:33 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.