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

Request #3451 Use http_build_query
Submitted: 2005-02-13 01:47 UTC
From: atrus Assigned: quipo
Status: Closed Package: Pager
PHP Version: Irrelevant OS: NA
Roadmaps: (Not assigned)    
Comments Add Comment Add patch

Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know! Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem : 32 - 27 = ?

 [2005-02-13 01:47 UTC] atrus
Description: ------------ Please use http_build_query instead of string concatenation. It handles arrays and objects correctly and it's behavior is more likely to be expected. Reproduce code: --------------- //example $arr = array( 'apple', 'orange' ); $pager = Pager::factory( array( 'extraVars' => array( 'arr' => $arr ) ) ); $links = $pager->getLinks(); echo $links[ first ]; //old code foreach ($qs as $name => $value) { $querystring[] = $name . '=' . $value; } $querystring = array_merge($querystring, array_unique($arrays)); $querystring = array_map('htmlentities', $querystring); return '?' . implode('&', $querystring) . (!empty($querystring) ? '&' : '') . $this->_urlVar .'='; //new code return '?' . htmlentities( http_build_query( $qs ) ); Expected result: ---------------- http://host.tld/script.php?arr[]=apple&arr[]=orange&pageId=1 Actual result: -------------- http://host.tld/script.php?arr=Array&pageId=1


 [2005-02-13 06:54 UTC] atrus
Code for loading http_build_query if it does not exist (so PHP_Compat is a dep only if php version < 5) if (!function_exists('http_build_query')) { require_once 'PHP/Compat.php'; PHP_Compat::loadFunction('http_build_query'); }
 [2005-02-16 17:41 UTC] quipo
It makes sense. In the meanwhile I fixed the bug.
 [2005-04-01 13:15 UTC] quipo
This bug has been fixed in CVS. In case this was a documentation problem, the fix will show up at the end of next Sunday (CET) on In case this was a website problem, the change will show up on the website in short time. Thank you for the report, and for helping us make PEAR better. -- I ended up using a http_build_query() replacement since the standard function was too aggressive