knp-components: SolariumQuerySubscriber items iteration bug

Hi! I think i’ve found bug in \Knp\Component\Pager\Event\Subscriber\Paginate\SolariumQuerySubscriber::items

\Solarium\QueryType\Select\Result\Result::getIterator - returned \ArrayIterator object.

That’s why \Knp\Component\Pager\Pagination\AbstractPagination::valid - always returned false, because key($this->items) where items is \ArrayIterator returned null.

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 1
  • Comments: 18

Commits related to this issue

Most upvoted comments

Our team found that we were running into this issue after the update to PHP8, and it was breaking.

We so far have ended up applying this patch using https://github.com/cweagans/composer-patches

--- /dev/null
+++ ../src/Knp/Component/Pager/Pagination/AbstractPagination.php
@@ -155,7 +155,10 @@
     }
 
     public function offsetExists($offset): bool
-    {
+    {   
+        if (gettype($this->items) === 'object' && get_class($this->items) == 'ArrayIterator') {
+            return array_key_exists($offset, iterator_to_array($this->items));
+        }
         return array_key_exists($offset, $this->items);
     }

Sharing in case this helps someone with this issue or someone with the cycles to fix this.