#39496 [Com]: $_SESSION assignment to variable stops register data
ID: 39496
Comment by: judas dot iscariote at gmail dot com
Reported By: bartek at cpu-zeto dot com dot pl
Status: Open
Bug Type: Session related
Operating System: Windows XP
PHP Version: 5.2.0
New Comment:
This is the expected behaviuor.
$_SESSION is a "magical" superglobal.
if you attempt to
$_SESSION = $var
or
$var = $_SESSION
it will loose it's magical atributes, for your own benefit.
It will not let you to shoot yourself in the foot.
Previous Comments:
------------------------------------------------------------------------
[2006-11-13 14:01:29] bartek at cpu-zeto dot com dot pl
Description:
------------
If you assign $_SESSION to variable you can't register more data after
assignment and it differs even on kind of a variable local or static.
If you place assignments between registering data, you can't: 1) to a
static varable ex.: self::$var you can't register data after that
assignments, 2) to local variable $var=$_SESSION you can't register
data before and after. But there is workaround you should assign with
casting to array: $var = (array)$_SESSION in both cases.
Reproduce code:
---------------
// 1 - seperate code
$_SESSION["test1"] = "test1";
self::$var = $_SESSION;
$_SESSION["test2"] = "test2";
// 2 - seperate code
$_SESSION["test1"] = "test1...";
$var = $_SESSION;
$_SESSION["test2"] = "test2...";
//workaround
$_SESSION["test1"] = "test1...";
$var = (array)$_SESSION;
self::$var = (array)$_SESSION;
$_SESSION["test2"] = "test2...";
Expected result:
----------------
I expect register data to $_SESSION after assignments $_SESSION to some
variable.
Actual result:
--------------
It's not
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=39496&edit=1
Thread (3 messages)