Is the order of the keys-value pairs in the $_GET superglobal variable guaranteed to be consistent with how the field-value pairs were received in the requested URL?
For example, given this URL request received by the web server:
index.php?a=1&foo=bar&b=2
...and this code:
foreach ($_GET as $key => $value)
{
echo $key . ": " . $value\n";
}
...will the result always be guaranteed to be:
a: 1
foo: bar
b: 2
I didn't see any mention of key ordering in the PHP doc of $_GET or superglobals in general. This leads me to believe that the order of the key-value pairs cannot be relied upon.
Does anyone know if the order has a guaranteed consistency to it, or better yet point to spec/doc that clarifies this?
It is best to assume that they are not reliable for two reasons. First, this is not documented. Things which are not documented are subject to change without notice... because if they never notified you the first time, why do the need to now? Second, you can't be 100% positive that the client won't somehow mung the data.
Yes, it will. You can check source code at main/php_variables.c, function "SAPI_TREAT_DATA_FUNC". There is a simple loop that reads variables from query string in order, then adds them to superglobals array (in order, with php_register_variable_ex()) if they pass filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With