ZF-3873: Zend_Paginator sets an incorrect lastItemNumber when using the Null adapter.

Description

When using Zend_Paginator_Adapter_Null, Zend_Paginator::_pages->lastItemNumber is set incorrectly. This is because Zend_Paginator_Adapter_Null::getItems() returns an empty array, which Zend_Paginator::getItemsByPage() casts to an empty ArrayIterator, which, in turn, sets Zend_Paginator::_pages->lastItemNumber to an incorrect number. Shouldn't Zend_Paginator_Adapter_Null::getItems() return an array containing the number of empty values equal to Zend_Paginator_Adapter_Null::_count ? Am I overlooking something?

Here's a patch:

Index: Paginator/Adapter/Null.php

--- Paginator/Adapter/Null.php (revision 10727) +++ Paginator/Adapter/Null.php (working copy) @@ -58,7 +58,7 @@ */ public function getItems($offset, $itemCountPerPage) { - return array(); + return array_slice(array_fill(0, $this->_count, ''), $offset, $itemCountPerPage); }

 /**

Comments

Thanks for the excellent bug report, Jim!

Fixed this in revisions 10791-10793.

sorry, the bug still here.

return array_slice(array_fill(0, $this->_count, ''), $offset, $itemCountPerPage); work fine. or better way to do it: public function getItems($offset, $itemCountPerPage) { $remainItemCount = $this->_count > $offset ? $this->_count - $offset : 0; $currentItemCount = $remainItemCount > $itemCountPerPage ? $itemCountPerPage : $remainItemCount; return array_fill(0, $currentItemCount, null); }

Test code:

$paginator = Zend_Paginator::factory(2); $paginator->setCurrentPageNumber(1); $paginator->setItemCountPerPage(5);

$pages = $paginator->getPages();

Zend_Debug::dump($pages);

--- except result --- ["currentItemCount"] => int(2) ["lastItemNumber"] => int(2)

--- actual result --- ["currentItemCount"] => int(5) ["lastItemNumber"] => int(5)

array_fill cannot accept zeor:

    if ($this->_count <= $offset) return array();
    $remainItemCount = $this->_count - $offset;
    $currentItemCount = $remainItemCount > $itemCountPerPage ? $itemCountPerPage : $remainItemCount;
    return array_fill(0, $currentItemCount, null);

Resolved in r17281