Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 2.5.1

Request #6986 On bad pageID to getPageData, return empty array instead of FALSE.
Submitted: 2006-03-02 00:19 UTC
From: remi at metacore dot net Assigned: quipo
Status: Closed Package: Pager (version 2.3.6)
PHP Version: 5.1.1 OS: Linux 2.4.27-2-686
Roadmaps: (Not assigned)    
Subscription  


 [2006-03-02 00:19 UTC] remi at metacore dot net (Remi Broemeling)
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.

Comments

 [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(); }
 [2006-03-02 14:44 UTC] User who submitted this comment has not confirmed identity
If you submitted this note, check your email.If you do not have a message, click here to re-send
MANUAL CONFIRMATION IS NOT POSSIBLE.  Write a message to pear-dev@lists.php.net
to request the confirmation link.  All bugs/comments/patches associated with this

email address will be deleted within 48 hours if the account request is not confirmed!