note 73844 added to ref.session

From: Date: Mon, 12 Mar 2007 21:06:58 +0000
Subject: note 73844 added to ref.session
Groups: php.notes 
Request: Send a blank email to php-notes+get-124388@lists.php.net to get a copy of this message
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"; ?> ---- Server IP: 69.147.83.197 Probable Submitter: 128.192.83.117 ---- Manual Page -- http://www.php.net/manual/en/ref.session.php Edit -- https://master.php.net/note/edit/73844 Del: integrated -- https://master.php.net/note/delete/73844/integrated Del: useless -- https://master.php.net/note/delete/73844/useless Del: bad code -- https://master.php.net/note/delete/73844/bad+code Del: spam -- https://master.php.net/note/delete/73844/spam Del: non-english -- https://master.php.net/note/delete/73844/non-english Del: in docs -- https://master.php.net/note/delete/73844/in+docs Del: other reasons-- https://master.php.net/note/delete/73844 Reject -- https://master.php.net/note/reject/73844 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#124388) next »