Bug #64724 [Opn]: Objects stored in Sessions sometimes get "lost".

From: Date: Sat, 27 Apr 2013 15:45:48 +0000
Subject: Bug #64724 [Opn]: Objects stored in Sessions sometimes get "lost".
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-178678@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=64724&edit=1

 ID:                 64724
 Updated by:         laruence@php.net
 Reported by:        php dot bugs at lippe-net dot de
 Summary:            Objects stored in Sessions sometimes get "lost".
 Status:             Open
 Type:               Bug
-Package:            Session related
+Package:            *General Issues
 Operating System:   Debian Wheezy
 PHP Version:        5.4.14
-Assigned To:        
+Assigned To:        mike
 Block user comment: N
 Private report:     N

 New Comment:

maybe due to the serialize


Previous Comments:
------------------------------------------------------------------------
[2013-04-26 15:04:24] php dot bugs at lippe-net dot de

Description:
------------
The "transactions" array of the $_SESSION variable is initialized only once.

If you repeat the invocation of the script. After a while the array contains some 
elements that are no more Objects of "class S" but references (for example 
r:5607;).



Test script:
---------------
<?php

class S implements \Serializable {

	protected $data = [];

	public function __construct() {
		for ( $i = 0; $i <= mt_rand(4, 7); $i++ ) {
			$this->data[] = mt_rand(0, 50);
		}
	}

	public function serialize() {
		return serialize($this->data);
	}

	public function unserialize($data) {
		$this->data = unserialize($data);
	}

}

session_name("testS");
session_start();

if ( empty($_SESSION["transactions"]) ) {
	$_SESSION["transactions"] = [ new S(), new S(), new S(), new S() ];
}

echo serialize($_SESSION);

?>

Expected result:
----------------
Example (first call):
transactions|a:4:{i:0;C:1:"S":76:{a:8:
{i:0;i:9;i:1;i:24;i:2;i:23;i:3;i:46;i:4;i:29;i:5;i:4;i:6;i:44;i:7;i:14;}}i:1;C:1:"
S":51:{a:5:{i:0;i:11;i:1;i:45;i:2;i:12;i:3;i:10;i:4;i:21;}}i:2;C:1:"S":59:{a:6:
{i:0;i:47;i:1;i:5;i:2;i:40;i:3;i:35;i:4;i:29;i:5;i:14;}}i:3;C:1:"S":58:{a:6:
{i:0;i:20;i:1;i:20;i:2;i:7;i:3;i:44;i:4;i:7;i:5;i:27;}}}

Actual result:
--------------
Example (after some roundabout 50 calls):

transactions|a:4:{i:0;r:5607;i:1;r:5617;i:2;r:5624;i:3;r:5632;}


------------------------------------------------------------------------



-- 
Edit this bug report at https://bugs.php.net/bug.php?id=64724&edit=1


Thread (8 messages)

« previous php.bugs (#178678) next »