Zend Framework

Iterator with zero items throws OutOfBoundsException

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.6.0RC3
  • Fix Version/s: 1.6.1, 1.10.2
  • Component/s: Zend_Paginator
  • Labels:
    None

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:

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

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

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:

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?

Issue Links

Activity

Hide
Matthew Ratzloff added a comment -

Fixed in revision 11222.

Show
Matthew Ratzloff added a comment - Fixed in revision 11222.
Hide
Michael Rehbein added a comment -

Issue appears to exist still in the null paginator.

Show
Michael Rehbein added a comment - Issue appears to exist still in the null paginator.
Hide
Michael Rehbein added a comment -

Attached patch includes

  • unit tests for Null, Array and Iterator Paginator
  • fix for Null Paginator if item count == 0
Show
Michael Rehbein added a comment - Attached patch includes
  • unit tests for Null, Array and Iterator Paginator
  • fix for Null Paginator if item count == 0
Hide
Matthew Weier O'Phinney added a comment -

Patch applied in trunk and 1.10 release branch.

Show
Matthew Weier O'Phinney added a comment - Patch applied in trunk and 1.10 release branch.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: