php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37444 Session not saved if $_SESSION array assigned as a whole array
Submitted: 2006-05-15 08:09 UTC Modified: 2006-05-15 10:48 UTC
From: grueff at libero dot it Assigned:
Status: Not a bug Package: Session related
PHP Version: 5.1.4 OS: Win XP
Private report: No CVE-ID: None
 [2006-05-15 08:09 UTC] grueff at libero dot it
Description:
------------
If i put values in $_SESSION array by inserting them as array elements such as this:

$_SESSION["a"]="test";

All does function ok; but if i prepare a whole array of values and put it in the session such as this:

$prep=array("test1","test2","test3","test4");
$_SESSION=$prep;

NOTHING gets written in the session, and any subsequest pages loading the session will get an empty session array.

Reproduce code:
---------------
This writes the session
<?php
	session_start();
	$tize=array("uno","due","tre","quattro","cinque","sei");
	$_SESSION=$tize;
	print_r($_SESSION);
?>

This tries to read the session:
<?php
	session_start();
	print_r($_SESSION);
?>

Expected result:
----------------
Output the content of $tize array!

Actual result:
--------------
Outputs an empty array!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-15 08:23 UTC] tony2001@php.net
This is expected behaviour.
_SESSION arrays looses its magic characteristics when you overwrite it with another array.
 [2006-05-15 10:48 UTC] grueff at libero dot it
Excuse me, but why it is expected?

And why this is not mentioned in any part of the documentation?

And, again, why this was not the case in previous PHP versions?
 
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon May 23 15:05:45 2022 UTC