Re: POST and session vars w/ same name
| From: | Matthew Leingang | Date: | Sun, 03 Dec 2000 19:12:34 +0000 |
| Subject: | Re: POST and session vars w/ same name | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-28458@lists.php.net to get a copy of this message | ||
On Sun, 3 Dec 2000, Jeffrey Blaze wrote:
> Are there any known side-effects to having a local variable and a session
> variable with the same name?
Session variables are no different from any other global variables. When
defining a function, you open up a new name space that can have variables
of the same name as "outside." Global variables are only available or
mutable when you invoke the GLOBAL command.
So you can do:
<?php
function print_a() {
$a=3;
echo "\$a = ", $a, "\n";
}
$a = 4;
echo "\$a = ", $a, "\n";
print_a();
echo "\$a = ", $a, "\n";
?>
And you will get:
$a = 4
$a = 3
$a = 4
But your question seems to be about POST variables, not local variables.
Do a phpinfo and look for a variable called gpc_order (or
variables_order). That tells you what order the variables are defined.
Mine is "EGPCS", which stands for Environment, GET, POST, Cookie, and
Session.
A major side-effect to my having a POST variable and a session variable
with the same name would be that I would lose the POST variable. Or
at least the ability to call it as a simple variable. The two values may
still be in the arrays $HTTP_POST_VARS and $HTTP_COOKIE_VARS. Don't know.
I try to either take advantage of the variables order or code so that it
isn't an issue. If you don't want variables killing other ones, just
don't use the same names!
HTH,
Matt
----------------------------------------------------------------
Matthew Leingang http://www.math.rutgers.edu/
Rutgers University leingang@math.rutgers.edu
Department of Mathematics "This signature needs no quote."