diff --git a/src/PhpCollection/AbstractMap.php b/src/PhpCollection/AbstractMap.php index 20cb26d..0494b77 100644 --- a/src/PhpCollection/AbstractMap.php +++ b/src/PhpCollection/AbstractMap.php @@ -294,7 +294,7 @@ public function count() public function getIterator() { - return new \ArrayIterator($this->elements); + return new \ArrayIterator($this->elements ?: []); } protected function createNew(array $elements) diff --git a/src/PhpCollection/AbstractSequence.php b/src/PhpCollection/AbstractSequence.php index 5ce2bde..cf0fae1 100644 --- a/src/PhpCollection/AbstractSequence.php +++ b/src/PhpCollection/AbstractSequence.php @@ -355,11 +355,11 @@ public function count() public function getIterator() { - return new \ArrayIterator($this->elements); + return new \ArrayIterator($this->elements ?: []); } protected function createNew(array $elements) { return new static($elements); } -} \ No newline at end of file +} diff --git a/src/PhpCollection/Set.php b/src/PhpCollection/Set.php index 1d70acc..3d2c063 100644 --- a/src/PhpCollection/Set.php +++ b/src/PhpCollection/Set.php @@ -52,7 +52,7 @@ public function last() public function getIterator() { - return new \ArrayIterator(array_values($this->elements)); + return new \ArrayIterator(array_values($this->elements ?: [])); } public function addSet(SetInterface $set) @@ -446,4 +446,4 @@ private function insertElement($elem, $hash) $this->elements[$index] = $elem; $this->lookup[$hash][] = $index; } -} \ No newline at end of file +}