Issues

ZF-4151: Iterator with zero items throws OutOfBoundsException

Issue Type: Bug Created: 2008-09-01T08:56:25.000+0000 Last Updated: 2010-02-25T04:51:39.000+0000 Status: Resolved Fix version(s): - 1.6.1 (15/Sep/08)

  • 1.10.2 (24/Feb/10)

Reporter: Matthew Ratzloff (mratzloff) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Paginator

Related issues: - ZF-9260

Attachments: - zf4151.r21071.patch

Description

I've been playing around with Zend_Paginator using the Zend_Paginator_Adapter_Iterator. All went pretty good, until I passed Zend_Paginator 0 items/pages. I get the following exception:

{quote} exception 'OutOfBoundsException' with message 'Seek position 0 is out of range'

0 [internal function]: ArrayIterator->seek(0)

{quote}

Now this exception is not a suprise, after all......it's seeking 0. The question I have is how to handle this exception? I use a foreach loop in my view to iterate over each item in the paginator and that's what's causing the exception:

<pre class="highlight">
foreach ($this->paginator as $item){}

Should I always check if there are 0 pages/items in the view and not start the foreach loop? Doing so would require a check in each view to see if there's 0 or more items/pages. I don't like that solution.

Are there better ways to handle this exception?

Comments

Posted by Matthew Ratzloff (mratzloff) on 2008-09-03T20:19:23.000+0000

Fixed in revision 11222.

Posted by Michael Rehbein (tech13) on 2010-02-16T14:05:54.000+0000

Issue appears to exist still in the null paginator.

Posted by Michael Rehbein (tech13) on 2010-02-16T14:07:36.000+0000

Attached patch includes - unit tests for Null, Array and Iterator Paginator - fix for Null Paginator if item count == 0

Posted by Matthew Weier O'Phinney (matthew) on 2010-02-23T08:35:12.000+0000

Patch applied in trunk and 1.10 release branch.

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts