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

Issue Type: Bug Created: 2010-02-24T23:42:16.000+0000 Last Updated: 2010-02-25T07:13:26.000+0000 Status: Resolved Fix version(s): Reporter: Sven Franke (snef) Assignee: Jurrien Stutterheim (norm2782) Tags: - Zend_Paginator

Related issues: - ZF-4151



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:

<pre class="highlight">
// $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:

<pre class="highlight">
    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);


Posted by Ramon Henrique Ornelas (ramon) on 2010-02-25T04:51:39.000+0000

This problem has been fixed in 1.10.2


Try a simple test

<pre class="highlight">
foreach ($paginator as $value) {
    echo 'foo';   

Posted by Matthew Weier O'Phinney (matthew) on 2010-02-25T04:56:26.000+0000

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.

Posted by Sven Franke (snef) on 2010-02-25T05:29:12.000+0000

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!

Have you found an issue?

See the Overview section for more details.


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

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