It may appear to be overly awkward, but you're probably better off unsetting one element at a time rather than the entire $_POST array. Here's why: If you're using object-oriented programming, you may have one class use $_POST['alpha'] and another class use $_POST['beta'], and if you unset the array after first use, it will void its use in other classes. To be safe and not shoot yourself in the foot, just drop in a little method that will unset the elements that you've just used: For example:
private function doUnset()
{
unset($_POST['alpha']);
unset($_POST['gamma']);
unset($_POST['delta']);
unset($_GET['eta']);
unset($_GET['zeta']);
}
Just call the method and unset just those superglobal elements that have been passed to a variable or argument. Then, the other classes that may need a superglobal element can still use them.
However, you are wise to unset the superglobals as soon as they have
been passed to an encapsulated object.
$_POST
? – Tullycount
.$_POST = array();
and you are all set. – Prosper$_POST
you are doing something wrong. – Candelaria$_POST
is writable which is kind of stupid, it can make sense to clear it if you are using an interface like a class to read user input. – Disembarrass$_POST
in the first place? It doesn't make any sense at all. Dont post anything to the next page than. – Glauce$_POST
then simply don't. – Candelaria$_POST
aswell. It's a matter of encapsulation; clearing$_POST
after you've used it ensures no other part of the application has access to it; otherwise a random bug anywhere can expose the potentially critical data in$_POST
. – Prosperphp://input
, in case for example you don't want to deal with the silly "bracket[]
field names are arrays" thing and use duplicate input keys like the rest of the non-PHP programming world is able to. In that case I would just clear POST as the first step before repopulating it. – DisembarrassPOST
data can also be found in$_REQUEST
– Durga