PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » HTML » Pager » Bug #6986

On bad pageID to getPageData, return empty array instead of FALSE.

Details

Request #6986On bad pageID to getPageData, return empty array instead of FALSE.
Submitted2006-03-02 00:19 UTC
Fromremi at metacore dot net
Assignedquipo
StatusClosed
PackagePager
PHP Version5.1.1
OSLinux 2.4.27-2-686
Roadmaps(Not assigned)

Comments

[2006-03-02 00:19 UTC] remi at metacore dot net

Description:
------------
If you call getPageData() with a bad pageID (i.e. a non-existing page), it will return FALSE (which is not a valid foreach target) instead of an empty array; which in turn makes it necessary to have an extra check that is unnecessary if it would return an empty array.

Test script:
---------------
$smarty->assign('elements_to_display', $pager->getPageData($x));

... and then in the smarty template ...

{foreach from=$elements_to_display item=element}
... Display the element ...
{/foreach}

Expected result:
----------------
Rather than returning FALSE, if it would return an empty array(), then the problem could be avoided (the effect would be virtually the same; except that an empty array *is* a valid foreach target).

Actual result:
--------------
An error occurs: a boolean is not a valid foreach target. An easy work-around is:

{if $elements_to_display}
{foreach from=$elements_to_display item=element}
... Display the element ...
{/foreach}
{/if}

... but preferrably I'd like to not have to remember to do that.

[2006-03-02 00:22 UTC] remi at metacore dot net

As an addendum, the specific code change that I am looking for (in Common.php) is:

function getPageData($pageID = null)
{
$pageID = empty($pageID) ? $this->_currentPage : $pageID;

if (!isset($this->_pageData)) {
$this->_generatePageData();
}
if (!empty($this->_pageData[$pageID])) {
return $this->_pageData[$pageID];
}
- return false;
+ return array();
}