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
-- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php