diff --git a/src/ORM/ArrayList.php b/src/ORM/ArrayList.php index c1231fb6b..0e42855d4 100644 --- a/src/ORM/ArrayList.php +++ b/src/ORM/ArrayList.php @@ -844,7 +844,7 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L */ public function offsetSet($offset, $value) { - if ($offset == null) { + if ($offset === null) { $this->items[] = $value; } else { $this->items[$offset] = $value; diff --git a/tests/php/ORM/ArrayListTest.php b/tests/php/ORM/ArrayListTest.php index e28a03dfc..c6a586248 100644 --- a/tests/php/ORM/ArrayListTest.php +++ b/tests/php/ORM/ArrayListTest.php @@ -1251,4 +1251,14 @@ class ArrayListTest extends SapphireTest $this->assertNotEquals(range(1, $upperLimit), $list->toArray()); } + + public function testOffsetSet() + { + $list = new ArrayList(['first value', 'second value']); + $this->assertSame(2, $list->count()); + $list->offsetSet(0, 'new value'); + $this->assertSame(2, $list->count()); + $this->assertSame('new value', $list->offsetGet(0)); + $this->assertSame('second value', $list->offsetGet(1)); + } }