1--TEST-- 2__wakeup can replace a copy of the object referring to the root node. 3--FILE-- 4<?php 5/* This bug never happened, but adding this test to make sure that further changes to unserialize don't allow freeing the root in __wakeup. */ 6class Obj { 7 function __construct($a) { 8 $this->a = $a; 9 } 10 11 public function __wakeup() { 12 echo "Calling __wakeup\n"; 13 $this->a = "replaced"; 14 } 15} 16 17$a = new stdClass(); 18$a->obj = new Obj($a);; 19$serialized = serialize($a); 20printf("%s\n", $serialized); 21$unserialized = unserialize($serialized); 22var_dump($unserialized); 23--EXPECTF-- 24O:8:"stdClass":1:{s:3:"obj";O:3:"Obj":1:{s:1:"a";r:1;}} 25Calling __wakeup 26object(stdClass)#%d (1) { 27 ["obj"]=> 28 object(Obj)#%d (1) { 29 ["a"]=> 30 string(8) "replaced" 31 } 32} 33