Skip to content

Commit 071f6b6

Browse files
committed
Merge pull request #2098 from jakzal/finder-iterator
[Component][Finder] Documented potential pitfalls when using iterator_to_array() with Finder
2 parents 165220e + ce75b88 commit 071f6b6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

components/finder.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,17 @@ the Finder instance.
5353
:phpfunction:`iterator_to_array` method, or get the number of items with
5454
:phpfunction:`iterator_count`.
5555

56+
.. caution::
57+
58+
When searching through multiple locations passed to the
59+
:method:`Symfony\\Component\\Finder\\Finder::in` method, a separate iterator
60+
is created internally for every location. This means we have multiple result
61+
sets aggregated into one.
62+
Since :phpfunction:`iterator_to_array` uses keys of result sets by default,
63+
when converting to an array, some keys might be duplicated and their values
64+
overwritten. This can be avoided by passing ``false`` as a second parameter
65+
to :phpfunction:`iterator_to_array`.
66+
5667
Criteria
5768
--------
5869

0 commit comments

Comments
 (0)