Hmm, this is intriguing to me. However, since $SESSION is superglobal in scope, it doesn't particularly surprise me that the array is affected by your function when PHP is being told to register variables globally...
this behaviour is unique to $SESSION though, it does not effect $POST nor $GET. That is what made think there is something different about the $_SESSION superglobal.
As a practical matter, i discovered this while putting together a function that cleans up arrays. I wanted to run various functions accross arrays (stripslashes, strip_tags, trim). I wanted to selectively decide on each use of the function whether or not the changes wrote back to array or simply placed all of the cleaned up variables into the global scope. I accomplished this by having the function return the array and on certain uses return the output of the function and other cases not. for example:
function cleanup ($array)
{
foreach ($array as $key => $value)
{
$value = strip_tags ($value);
$value = stripslashes ($value);
$value = htmlspecialchars ($value);
$value = trim ($value);
$array[$key] = $value;
$GLOBALS[$key] = $value;
}
return $array;
}
// only put cleaned up variables in global scope
cleanup ($_SESSION);
// write cleaned up variables back to array
$_SESSION = cleanup ($_SESSION);
this works fine with register_globals OFF but with register_globals ON the changes always get written back to the $SESSION array regardless of whether or not I spool the output of the function back to $SESSION.
I guess the only workaround is the use temp arrays