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

Request #6986 On bad pageID to getPageData, return empty array instead of FALSE.
Submitted: 2006-03-01 19:19 UTC Modified: 2006-03-02 09:44 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-01 19: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-01 19: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 09:44 UTC] quipo
This bug has been fixed in CVS. If this was a documentation problem, the fix will appear on pear.php.net by the end of next Sunday (CET). If this was a problem with the pear.php.net website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better.