From ad87890b2e92f3f4092bbf9a70ab0d439d40ce31 Mon Sep 17 00:00:00 2001 From: Sam Minnee Date: Tue, 2 Oct 2018 09:54:06 +1300 Subject: [PATCH] =?UTF-8?q?FIX:=20Don=E2=80=99t=20change=20state=20in=20Ar?= =?UTF-8?q?rayList::getIterator()?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This prevents the map-to-ArrayData conversion from changing object state and making the result of toArray() non-deterministic. Fixes #2636. Other solutions were suggested on that ticket, but there is no way of putting special code in for a SSViewer-specific iterator, and having object state pre-emptively converted to ArrayData would be an SS5-level change. --- src/ORM/ArrayList.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/ORM/ArrayList.php b/src/ORM/ArrayList.php index 70edb5b9e..9ac0558e2 100644 --- a/src/ORM/ArrayList.php +++ b/src/ORM/ArrayList.php @@ -84,12 +84,13 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L */ public function getIterator() { - foreach ($this->items as $i => $item) { - if (is_array($item)) { - $this->items[$i] = new ArrayData($item); - } - } - return new ArrayIterator($this->items); + $items = array_map( + function ($item) { + return is_array($item) ? new ArrayData($item) : $item; + }, + $this->items + ); + return new ArrayIterator($items); } /**