note 37381 added to ref.session

From: Date: Wed, 12 Nov 2003 20:49:20 +0000
Subject: note 37381 added to ref.session
Groups: php.notes 
Request: Send a blank email to php-notes+get-60318@lists.php.net to get a copy of this message
I found the following interesting feature. I am using $_SESSION array for storing state information between scripts. The values from $_SESSION were assigned to normal variables as per usual. However, I found that the $_SESSION values were being changed to the value of the assigned local variable. i.e. $_SESSION["foo"] = 5 $foo = $_SESSION["foo"]; $foo = 2; NOW $_SESSION["foo"] will equal 2. The local variable $foo is a reference to $_SESSION. It is NOT a copy. This can obviously cause problems if one is not aware of it. There is some information on a similar item involving the $_GLOBAL array and local variables at http://mx.php.net/manual/en/language.variables.scope.php ---- Manual Page -- http://www.php.net/manual/en/ref.session.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+37381 Delete -- http://master.php.net/manage/user-notes.php?action=delete+37381&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+37381&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#60318) next »