Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10267 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 58575 invoked by uid 1010); 4 Jun 2004 14:15:12 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 58510 invoked from network); 4 Jun 2004 14:15:11 -0000 Received: from unknown (HELO conan.ard.nu) (217.148.166.184) by pb1.pair.com with SMTP; 4 Jun 2004 14:15:11 -0000 Received: from [127.0.0.1] (helo=iamjochem.com) by conan.ard.nu with esmtp (Exim 4.32) id 1BWFTS-0000DU-LB; Fri, 04 Jun 2004 16:15:10 +0200 Message-ID: <40C083EE.9030304@iamjochem.com> Date: Fri, 04 Jun 2004 16:15:10 +0200 User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6) Gecko/20040113 X-Accept-Language: en-us, en MIME-Version: 1.0 To: Sara Golemon , php internals References: <40BE1285.9010701@iamjochem.com> <20040602204304.35253.qmail@pb1.pair.com> <40BF5A18.9020101@iamjochem.com> <20040603180803.77866.qmail@pb1.pair.com> In-Reply-To: <20040603180803.77866.qmail@pb1.pair.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Re: http_build_query unexpected/bad behaviour From: jochem@iamjochem.com (Jochem Maas) Sara, just a quick thankyou for taking the time to explain! and to say that I will be adding some sanity checks around my use of http_build_query() to avoid passing it arrays whose 'endpoints' are empty arrays as there is obviously nothing broken here kind regards, Jochem Maas Sara Golemon wrote: >>>>the issue is that the array $y below results in an empty string: >>>> >>>>$x = array('e' => array('kf' => '')); >>>>$y = array('e' => array('kf' => array())); >>>> >>>>echo '\''. http_build_query($x). "'\n"; >>>>echo '\''. http_build_query($y) . "'\n"; >>>> >> >>my original assumption was that both cases would produce the same >>result. I don't see the rationale (although internally it may be >>obvious) that the second array 'resolves' (is that the correct use of >>the word?) into an empty string. - >> > > Let's look at them then: > > $x becomes `e[kf]=` which is to say "make e an array containing an empty > string at offset kf" > > In the case of $y, the closest thing you could come to would be `e[kf][]=` > which says "make e an array containing another array at offset kf which > contains an empty string." This is not precisely the same as what's > represented in the original $y variable. If we were to process that query > string into variables we'd get back array('e'=>array('kf'=>array(''))).... > *close* but no cigar. > > The problem is that array creation from a query string relies on implicit > array creation and there is no way to implicitly create an empty array. > > >>an empty string is a valid value for a param coming from the POST/GET >>request, php's loose nature lead me to assume the an empty array in such >>a context would result in at least the some output - I went with the >>feeling that an empty array is not emptier than an empty string. >> > > It is in the sense that query strings don't honestly have a concept of > arrays. So you can feed a query string an empty string and it says "Oh! An > empty string! How nice!" but an empty array is so far outside of its > understand it'll just stare at you and wonder what's going through your > mind. > > It's *possible* to change the behavior of http_build_query() to treat an > empty array as an array containing an empty string as its only element. But > that is the sort of thing to lead to severely unexpected behavior and is > probably not the way to go. > > -Sara >