note 37381 deleted from ref.session by nlopess
| From: | nlopess@php.net | Date: | Fri, 12 Mar 2004 14:41:03 +0000 |
| Subject: | note 37381 deleted from ref.session by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-66726@lists.php.net to get a copy of this message | ||
Note Submitter: simonc no spam at linux mail org
----
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