[ACCEPTED]-Why would you merge $_GET and $_POST in PHP?-array-merge

Accepted answer
Score: 20

That is because the default $_REQUEST is a merger 10 of $_GET, $_POST AND $_COOKIE. Also, the order in which the 9 variables of these superglobals are merged 8 into $_REQUEST is dependant on the ini setting variables_order and 7 as of PHP 5.3.0 can also be influenced by 6 request_order. So my guess is, that the developer wanted 5 to make sure $_REQUEST consists of only $_GET and $_POST, merged 4 in that particular order, if he didn't have 3 access to ini settings (on a shared host 2 for instance). You see, variables_order and request_order aren't configurable 1 on a per script basis.

HTH

Score: 6

$_REQUEST contains the contents of $_GET, $_POST, and $_COOKIE arrays 3 by default. Maybe they want to exclude COOKIE 2 variables from it, since it is generally 1 not used for that purpose.

Score: 2

This is so if you have a GET variable and 4 a POST variable with the same name, it will 3 choose the POST variable over the GET one.

Also 2 you may not want the cookies in the $_REQUEST 1 variable.

Score: 1

I don't know specifically why it was done 17 where you saw it, but I have seen that done 16 before when some processing has been done 15 on the values in one array or another and 14 you want to merge those changes back into 13 $_REQUEST so that anyone using $_REQUEST 12 will get the changes even though they were 11 done to the $_POST or $_GET variables.

This 10 comes up in situations like Wordpress has 9 because plugin developers could be using 8 any of those variables to access data and 7 the Wordpress core would need to make sure 6 they all get the same data.

Why wouldn't 5 you want to do it to $_REQUEST directly? Because 4 $_REQUEST contains a ton of extra info that 3 $_POST and $_GET don't have. You might not 2 want to apply your processing to all those 1 extra bits.

More Related questions