1--TEST-- 2Bug #79031: Session unserialization problem 3--FILE-- 4<?php 5 6class SerializableClass implements Serializable { 7 public $sharedProp; 8 public function __construct($prop) 9 { 10 $this->sharedProp = $prop; 11 } 12 public function __set($key, $value) 13 { 14 $this->$key = $value; 15 } 16 public function serialize() 17 { 18 return serialize(get_object_vars($this)); 19 } 20 public function unserialize($data) 21 { 22 $ar = unserialize($data); 23 if ($ar === false) { 24 return; 25 } 26 foreach ($ar as $k => $v) { 27 $this->__set($k, $v); 28 } 29 } 30} 31 32// Shared object that acts as property of two another objects stored in session 33$testPropertyObj = new stdClass(); 34$testPropertyObj->name = 'test'; 35 36// Two instances of \SerializableClass that shares property 37$sessionObject = [ 38 'obj1' => new SerializableClass($testPropertyObj), 39 'obj2' => new SerializableClass($testPropertyObj), 40]; 41session_start(); 42$_SESSION = $sessionObject; 43 44$sessionString = session_encode(); 45session_decode($sessionString); 46echo $sessionString; 47echo "\n\n"; 48var_dump($_SESSION); 49 50?> 51--EXPECT-- 52obj1|C:17:"SerializableClass":65:{a:1:{s:10:"sharedProp";O:8:"stdClass":1:{s:4:"name";s:4:"test";}}}obj2|C:17:"SerializableClass":28:{a:1:{s:10:"sharedProp";r:3;}} 53 54array(2) { 55 ["obj1"]=> 56 object(SerializableClass)#4 (1) { 57 ["sharedProp"]=> 58 object(stdClass)#5 (1) { 59 ["name"]=> 60 string(4) "test" 61 } 62 } 63 ["obj2"]=> 64 object(SerializableClass)#6 (1) { 65 ["sharedProp"]=> 66 object(stdClass)#5 (1) { 67 ["name"]=> 68 string(4) "test" 69 } 70 } 71} 72