note 73844 deleted from ref.session by danbrown
| From: | danbrown@php.net | Date: | Sun, 20 Jul 2008 16:43:50 +0000 |
| Subject: | note 73844 deleted from ref.session by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142191@lists.php.net to get a copy of this message | ||
Note Submitter: jphansen at uga dot edu
----
I wanted to retain a session variable's value after a session_unset() and encountered this
anomaly: PHP can assign your variable by reference/pointer if your data source is a session
variable, even if "&" isn't supplied.
<?
$_SESSION['x'] = "foo";
$x = $_SESSION['x'];
echo $x; // "foo"
$_SESSION['x'] = "bar";
echo $x; // "bar";
?>
To fix this, you can assign your variable to a new variable:
<?
$_SESSION['x'] = "foo";
$x = $_SESSION['x'];
$y = $x;
echo $y; // "foo"
$_SESSION['x'] = "bar";
echo $y; // "foo";
?>