Skip to content
Permalink
Browse files

Fix collections when iterating over certain classes

When a class that extends the base ArrayIterator class are iterated
over, the collection class would replace the class with a basic array or
ArrayIterator, breaking any custom logic in the original class.

This fixes the issue by checking if the class is an ArrayIterator,
rather than if it is simply a instance of ArrayIterator.
  • Loading branch information...
dakota committed Nov 1, 2017
1 parent 1f09411 commit 2db64da16099d4aa335e8a3fa35f56634cd8d1c6
@@ -512,7 +512,7 @@ public function insert($path, $values)
public function toArray($preserveKeys = true)
{
$iterator = $this->unwrap();
if ($iterator instanceof ArrayIterator) {
if (get_class($iterator) === ArrayIterator::class) {
$items = $iterator->getArrayCopy();
return $preserveKeys ? $items : array_values($items);
@@ -819,7 +819,7 @@ protected function optimizeUnwrap()
{
$iterator = $this->unwrap();
if ($iterator instanceof ArrayIterator) {
if (get_class($iterator) === ArrayIterator::class) {
$iterator = $iterator->getArrayCopy();
}
@@ -88,7 +88,7 @@ public function unwrap()
$iterator = $iterator->unwrap();
}
if (!$iterator instanceof ArrayIterator) {
if (get_class($iterator) !== ArrayIterator::class) {
return $this;
}
@@ -74,7 +74,7 @@ public function unwrap()
$iterator = $iterator->unwrap();
}
if (!$iterator instanceof ArrayIterator) {
if (get_class($iterator) !== ArrayIterator::class) {
return $filter;
}
@@ -86,7 +86,7 @@ public function unwrap()
$iterator = $iterator->unwrap();
}
if (!$iterator instanceof ArrayIterator) {
if (get_class($iterator) !== ArrayIterator::class) {
return $this;
}
@@ -97,7 +97,7 @@ public function unwrap()
$iterator = $iterator->unwrap();
}
if (!$iterator instanceof ArrayIterator) {
if (get_class($iterator) !== ArrayIterator::class) {
return $this;
}

0 comments on commit 2db64da

Please sign in to comment.
You can’t perform that action at this time.