Skip to content

Loading…

DDC-2178: Last hydrated element is passed by reference #2870

Closed
doctrinebot opened this Issue · 3 comments

2 participants

@doctrinebot

Jira issue originally created by user menshinskiym:

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.

@doctrinebot

Comment created by @beberlei:

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

@doctrinebot

Issue was closed with resolution "Can't Fix"

@doctrinebot

Comment created by menshinskiym:

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.

@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot closed this
@doctrinebot doctrinebot added the Bug label
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.