php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #39496 $_SESSION assignment to variable stops register data
Submitted: 2006-11-13 14:01 UTC Modified: 2006-11-14 08:09 UTC
From: bartek at cpu-zeto dot com dot pl Assigned:
Status: Not a bug Package: Session related
PHP Version: 5.2.0 OS: Windows XP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bartek at cpu-zeto dot com dot pl
New email:
PHP Version: OS:

 

 [2006-11-13 14:01 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-11-14 02:56 UTC] judas dot iscariote at gmail dot com
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.
 [2006-11-14 08:09 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 20:01:35 2025 UTC