mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Iterate undefined offset 0 #5037
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @iskyd on GitHub (Mar 7, 2016).
From my function i return by a native query and iterator :
return $q->iterate();Now in accordance with documentation :
But after the first execution i get :
If i dump $row variable i notice that the first execution i get from $row[0] the second $row[1] and so on...
@ghost commented on GitHub (Sep 23, 2016):
I think you're right, because I noticed the same. For others having this issue: You could try
$iterator->key()for the currently valid index of$row.But it would be more intuitive, if
$rowwould already contain the correct value, instead of an array, imo (maybe there are cases idk about yet which make it necessary).@flack commented on GitHub (Oct 5, 2017):
I just stumbled across this, too: It happens if your hydration mode is not
HYDRATE_OBJECT, i.e. if you iterate over objects, it works as documented, but for e.g. array results, you'll get this error@flack commented on GitHub (Oct 5, 2017):
Seems to be the same as #3238.
@Ocramius is this intended behavior?
@lcobucci commented on GitHub (Nov 26, 2017):
@iskyd @whatda @flack could you please send us a failing test case that reproduces that behaviour? It would help us a lot to identify and fix the issue you're describing.
You can find examples on
388afb46d0/tests/Doctrine/Tests/ORM/Functional/Ticket@flack commented on GitHub (Nov 26, 2017):
@lcobucci I can make a unittest if you want, but it's really very simple. The code to reproduce is right there in the ticket description
@lcobucci commented on GitHub (Nov 26, 2017):
@flack so, please, send us a PR 👍
@Steveb-p commented on GitHub (Jan 8, 2018):
I've stumbled across this as well with exactly the same situation.
iterateworks alright if you're using object hydration, and at the point when you start using arrays (for me I just needed the ID)iteratestarts using 0,1,2,3... as keys.Question is it this intended behavior. For people already going around this issue it will be kind of a BC break.
@peter-gribanov commented on GitHub (Feb 1, 2019):
I solve this problem using the
current()function. But i agree. This is a very strange behavior.@beberlei commented on GitHub (Dec 5, 2020):
This is fixed by moving to the new method
Query::toIterablein 2.8