Ok so after reading the latest docs on the 4.1.x php I see that the recommended way to access POST, GET, SESSION and COOKIE data is via the $SESSION, $COOKIE, etc "variables" The idea being that these are the only fully global references and one can then disable register global veriables in php to reduce security problems.
Any way, my question is what context do these variables are?
EXAMPLE
Now there examples are assumed if you test the script by calling the url ex1.php?test=3 as to pass in the GET variable.
<?
//EXAMPLE 1
function test_global() {
global $HTTP_GET_VARS, $_GET;
echo "<br>step3=" . $HTTP_GET_VARS['test'];
echo "<br>step4=" . $_GET['test'];
}
function test_nonglobal() {
echo "<br>step5=" . $HTTP_GET_VARS['test'];
echo "<br>step6=" . $_GET['test'];
}
echo "<br>step1=" . $HTTP_GET_VARS['test'];
echo "<br>step2=" . $_GET['test'];
test_global();
test_nonglobal();
?>
The output from the above is
step1=3
step2=3
step3=3
step4=3
step5=
step6=3
SO in step6 , the nonglobal test, we see that the $GET is somehow global. OK so what up wit dat?
So we all know that an unset() in a fuinction only removes the reference to the global variable, so what happens if we do an unset on the $GET beast? I don't know?
Once again test by passing the GET veriable in the url ex2.php?test=3
<?
//EXAMPLE 2
function test_unset() {
unset($GET['test']);
echo "<br>step7=" . $GET['test'];
}
test_unset();
echo "<br>step8=" . $_GET['test'];
?>
What do we get here for output?
step7=
step8=
Which means it actually did unset - unlike what unset should do to a globalized variable in a function,
What about this...remember call with ex3.php?test=3 to pass it GET var
<?
//EXAMPLE 3
function test_unset() {
unset($GET);
echo "<br>step9=" . $GET['test'];
}
test_unset();
echo "<br>step10=" . $_GET['test'];
?>
What do we get here for output?
step9=3
step10=3
WTH? This is a little odd, no? That does not work. It does not unset the array inside or outside the function.
I guess these $_GET type variable arrays are just things you cannot unset, and are totally global to functions.
Anyway I was just trying to figure how these guys behaved and why so I put it in here just in case someone else is scrathing their head thinking they are going nuts.
I have an understanding of how they behave now but i would still like to know how they fit in with the rest of the variables in php and why are these different.
Thanks