1

What is the proper way to clear super-global variable in PHP?

Is this way correct?

$_GET = array(); 

Or should I use this way?

foreach ($_GET as $k => $v) {
  unset($_GET[$k]);
}
braX
  • 11,506
  • 5
  • 20
  • 33
NoSkill
  • 718
  • 5
  • 15
  • 2
    You don't. Or it would be weird and useless if your try to, because those are automatic created variables, see: http://php.net/manual/en/language.variables.superglobals.php – Rizier123 Dec 09 '16 at 15:45
  • 2
    Or `unset($_GET);`. But why? – AbraCadaver Dec 09 '16 at 15:45
  • FYI, that dupe applies to all superglobals – Machavity Dec 09 '16 at 15:46
  • 1
    Short answer: Both suggested ways should work. Longer answer: Just don't. There must be a better way to solve whatever it is you need to solve. – apokryfos Dec 09 '16 at 15:46
  • @apokryfos Yeah, i think this is an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem/66378#66378) – Machavity Dec 09 '16 at 15:47
  • Don't use global variables. Global variables are evil. Save your parse $_GET in your own array use it instead of global var. – lamik Dec 09 '16 at 16:01

0 Answers0