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

Request #3451 Use http_build_query
Submitted: 2005-02-12 20:47 UTC Modified: 2005-04-01 07:15 UTC
From: atrus Assigned: quipo
Status: Closed Package: Pager
PHP Version: Irrelevant OS: NA
Roadmaps: (Not assigned)    
Subscription  


 [2005-02-12 20: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

Comments

 [2005-02-13 01: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 12:41 UTC] quipo
It makes sense. In the meanwhile I fixed the bug.
 [2005-04-01 07: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 pear.php.net. In case this was a pear.php.net 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