strange thing in PHP session variable and local variable
Summary
During PHP web application development, a peculiar issue arose where assigning a value to a local variable named $user inexplicably altered the $_SESSION["user"] variable. This behavior manifested when attempting to display a user profile based on a query parameter. The unexpected interaction between the local and session variables ceased upon renaming the local variable from $user to $user_id. The underlying cause for this scope-crossing phenomenon, however, remains an unresolved mystery.
The situation is described below:
I want to display a user's profile using a query parameter user=user_id as the parameter. And also the session variable when user logs in is $_SESSION["user"].So before displaying the user's profile, I need to either get the query string parameter user and create a local variable called $user and assign value to it as $user=$_REQUEST["user"].Here comes the strange thing,every time after the local variable $user is changed,the session variable $_SESSION["user"] is also changed to the value of $user. How come?But after i change the variable name from $user to $user_id, all strange things are gone.
The reason why this happens still remains as a mystery. Some more effort will be taken to find the reason.Keep going1
If any of you knows the reason.You can post it on the comment window. I appreciate your help.
No comment for this article.