ZF-9260: Paginator (NULL adapter) fails when number of items is 0.


When using Zend_Paginator I ran into a problem since the 1.10.x versions.

In some 1.9.x code I'm using something like this:

// $total is set some where in the code, could be some query result.
// After some code, we get the following 'settings'.
$total = 0;
$page = 1;
$itemsPerPage = 5;

// Create paginator with null adapter.
$paginator = new Zend_Paginator(new Zend_Paginator_Adapter_Null($total));

// Get in in view.
$this->view->paginator = $paginator;

Works fine in 1.9.x, in 1.10.x I get an error because of some array error.

In the NULL adapter, the getItems() function was changed.

I think the 'problem' could be solved by adding a check for 0 items. In the current code (1.10.2), there is only a check for "$offset > $this->count()". When the count = 0, it should also return an empty array:

    public function getItems($offset, $itemCountPerPage)
        if ($this->count() == 0 || $offset > $this->count()) {
            return array();

        $remainItemCount  = $this->count() - $offset;
        $currentItemCount = $remainItemCount > $itemCountPerPage ? $itemCountPerPage : $remainItemCount;

        return array_fill(0, $currentItemCount, null);


This problem has been fixed in 1.10.2


Try a simple test

foreach ($paginator as $value) {
    echo 'foo';   

Sven, you indicate the issue also affects 1.10.2, but did you actually test against 1.10.2? As noted, this sounds like the same issue as reported in ZF-4151, which has already been resolved. Please let us know if this is not the case.

Ramon, Matthew...

I am so terribly sorry! Something went wrong with the svn-update of the Zend-lib, so it was not updated correctly :(

I was sure I was using 1.10.2, but in fact it still was 1.10.1!

I will go stand in some corner of the room for the rest of the day. Shame on me!