FIX: Don’t change state in ArrayList::getIterator()

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.
This commit is contained in:
Sam Minnee 2018-10-02 09:54:06 +13:00
parent 755907d117
commit ad87890b2e

View File

@ -84,12 +84,13 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
*/ */
public function getIterator() public function getIterator()
{ {
foreach ($this->items as $i => $item) { $items = array_map(
if (is_array($item)) { function ($item) {
$this->items[$i] = new ArrayData($item); return is_array($item) ? new ArrayData($item) : $item;
} },
} $this->items
return new ArrayIterator($this->items); );
return new ArrayIterator($items);
} }
/** /**