Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:10265 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 78663 invoked by uid 1010); 3 Jun 2004 18:08:09 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 77875 invoked by uid 1007); 3 Jun 2004 18:08:04 -0000 Message-ID: <20040603180803.77866.qmail@pb1.pair.com> To: internals@lists.php.net References: <40BE1285.9010701@iamjochem.com> <20040602204304.35253.qmail@pb1.pair.com> <40BF5A18.9020101@iamjochem.com> Date: Thu, 3 Jun 2004 11:08:03 -0700 Lines: 47 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 X-Posted-By: 169.229.135.175 Subject: Re: [PHP-DEV] Re: http_build_query unexpected/bad behaviour From: pollita@php.net ("Sara Golemon") > >>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