Session variable storage failure

Hello.

I could use some hints or ideas to solve an odd issue whereby I am losing session variables between requests. In one request I assign an array to the active session, and add a print of it as the very last line of the program to assure that it is still there. I add another print of $_SESSION directly following the start of the session in the next request, whence it is empty.

This only occurs upon having assigned this array to the session variable.

The array, as an element of $_SESSION, looks like the following being printed at the end of the first request;

["configuration|21|1"]=> array(15) 
{ 
[1]=> array(1) { [0]=> string(2) "28" } 
[2]=> array(1) { [0]=> string(2) "24" } 
etc 
}

EDIT:

It seems it functions without using vertical bars in the index. Though that I can assign it like that to begin with makes it somewhat unexpected. Will try to use a different array index.

I agree, it is confusing.

I tried to find an authoritative source in the documentation surrounding valid array key values, however it simply states ‘an integer or string’.

Obviously, using a string as an array key comes with a few caveats when used in certain places, $_POST, $_SESSION…

A safe bet would be stick to the definition for a valid variable name, and most folk do.

If I get a bit of time later this afternoon, I may have a little play to better educate myself.


$arr = array(
  'foo|foo' => 0,
  'bar.bar' => 1
);

print_r(
  $arr
);

/*
  Array
  (
      [foo|foo] => 0
      [bar.bar] => 1
  )
*/

echo $arr['foo|foo']; #0
echo $arr['bar.bar']; #1

foreach($arr as $k => $v){
  echo $k, '=', $v, "\
";
}
/*
  foo|foo=0
  bar.bar=1
*/

print_r(
  unserialize(serialize($arr))
);

/*
  Array
  (
      [foo|foo] => 0
      [bar.bar] => 1
  )
*/