php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37926 Session var don't get setted
Submitted: 2006-06-27 13:38 UTC Modified: 2007-02-26 11:06 UTC
Votes:11
Avg. Score:4.7 ± 0.4
Reproduced:11 of 11 (100.0%)
Same Version:11 (100.0%)
Same OS:3 (27.3%)
From: thomas at ecommerce dot com Assigned:
Status: Not a bug Package: Session related
PHP Version: 5.x OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: thomas at ecommerce dot com
New email:
PHP Version: OS:

 

 [2006-06-27 13:38 UTC] thomas at ecommerce dot com
Description:
------------
I didn't find anything in the documentation that is related to the following script. Its not possible to update the $_SESSION var after the call 'dummy($_SESSION)'.

The var will be set during the runtime, but when you refresh the page/script, the vars setted after the function call will be gone.

just put the bottom code in an test.php script and run it 1 time and refresh it again via browser. You will see, second var will be gone after refresh.

Reproduce code:
---------------
<?php
ob_start(); //-- enshure headers don't get sended
session_start(); //-- start session

//-- dummy function, that make it impossible to set an $_SESSION var after it
function dummy($var = null)
{
    static $tmp = array();

    $tmp[] = $var;
}

//-- dump current value
var_dump($_SESSION);

//-- set new value
$_SESSION['test'] = "cool";

//-- call dummy function
dummy($_SESSION);

//-- simeple var
$cool = "yes";

//-- set var in session
$_SESSION['whatever'] = $cool;

//-- dump current value
var_dump($_SESSION);

?>

Expected result:
----------------
Expected result after refresh:

array(2) {
  ["test"]=>
  string(4) "cool"
  ["whatever"]=>
  string(3) "yes"
}
array(2) {
  ["test"]=>
  string(4) "cool"
  ["whatever"]=>
  string(3) "yes"
}

Actual result:
--------------
Current result after refresh:

array(1) {
  ["test"]=>
  string(4) "cool"
}
array(2) {
  ["test"]=>
  string(4) "cool"
  ["whatever"]=>
  string(3) "yes"
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-27 13:39 UTC] thomas at ecommerce dot com
wrong subject
 [2006-06-28 09:47 UTC] thomas at ecommerce dot com
Same problem with this Code example:

<?php
ob_Start();
session_start();

var_dump($_SESSION);

$_SESSION['asdf'] = "cool";

$tmp = $_SESSION;

$cool = 'test';

$_SESSION['me'] = $cool;

var_dump($_SESSION);
 [2006-06-28 09:57 UTC] thomas at ecommerce dot com
Here is also an interesting issue:

When i use the 2nd example code ( the one with $tmp = $_SESSION);

and i put

unset($tmp);

after it or try to assign 
$tmp['x'] = 'y';

then the $_SESSION assignment startin again to work. Please investigatte ASAP.
 [2006-06-28 13:25 UTC] thomas at ecommerce dot com
Can i get a status update on this bug?
 [2006-06-28 13:29 UTC] tony2001@php.net
>Can i get a status update on this bug?
Yes. Don't try to outsmart session extension by changing $_SESSION array itself. This way $_SESSION looses its magical features and the only result you can get is invalid/broken data.
This is expected and I have serious doubts it's going to be changed ever.
 [2006-06-28 13:35 UTC] thomas at ecommerce dot com
Ok, but still, there is nothing in the documentation that explain this problem or show it, how to avoid it.

Moved to Documentation problem
 [2006-06-30 09:54 UTC] thomas at ecommerce dot com
So, does this get fixed at least in the documentation? :)

I still don't understand why this can't get fixed, a lot of user crys because of the 'magic feature' of the session and such problems.
 [2006-07-06 10:20 UTC] thomas at ecommerce dot com
Any status update on this bug??? Not hard to add in documentation

-.-
 [2006-07-06 10:25 UTC] thomas at ecommerce dot com
Updated information that this is general
 [2006-07-06 11:18 UTC] bjori@php.net
We welcome a patch from you.
I however don't see the need to document it, will only add 
confusion.
 [2006-11-07 14:08 UTC] mjwindsorREMOVE at CAPShotmail dot com
I do not agree that this is a documentation problem, or that describing it as ?expected behaviour? is a suitable response. If PHP is a robust language, it cannot have unexpected and obscure rules applied at random. $_SESSION should just be an array that persists between page requests, providing session_start() has been called: that is what everyone expects and that is how it is used.

In every other case, $new_array = $existing_array; is a value assignment and simply copies one array to another and no alteration is made or should be expected to $existing_array or its properties.

I have spent several days trying to work out why my sessions weren?t working as I expected and taken up the time of several helpful posters in various fora. I finally tracked the problem down to this issue and some code included in every page of a widely used forum; an otherwise robust and secure open source product. I seriously doubt that a note in the documentation would have saved me much of this work and none of the work needed to get around the issue, once it was identified. This will apply equally to all those who fall foul of this problem ? you need to know what the problem is before searches will turn up documentation.

Mike
 [2007-02-24 21:49 UTC] dmytton@php.net
As described above, adding a note is not appropriate as it will more than likely add confusion. 
 [2007-02-26 09:57 UTC] thomas at ecommerce dot com
Changed back to session related issue. Not fixed or commented yet
 [2007-02-26 11:06 UTC] tony2001@php.net
.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 06:01:35 2024 UTC