1--TEST-- 2__serialize() mechanism (004): Delayed __unserialize() calls 3--FILE-- 4<?php 5 6class Wakeup { 7 public $data; 8 public function __construct(array $data) { 9 $this->data = $data; 10 } 11 public function __wakeup() { 12 echo "__wakeup() called\n"; 13 var_dump($this->data); 14 $this->woken_up = true; 15 } 16} 17 18class Unserialize { 19 public $data; 20 public function __construct(array $data) { 21 $this->data = $data; 22 } 23 public function __serialize() { 24 return $this->data; 25 } 26 public function __unserialize(array $data) { 27 $this->data = $data; 28 echo "__unserialize() called\n"; 29 var_dump($this->data); 30 $this->unserialized = true; 31 } 32} 33 34$obj = new Wakeup([new Unserialize([new Wakeup([new Unserialize([])])])]); 35var_dump($s = serialize($obj)); 36var_dump(unserialize($s)); 37 38?> 39--EXPECT-- 40string(126) "O:6:"Wakeup":1:{s:4:"data";a:1:{i:0;O:11:"Unserialize":1:{i:0;O:6:"Wakeup":1:{s:4:"data";a:1:{i:0;O:11:"Unserialize":0:{}}}}}}" 41__unserialize() called 42array(0) { 43} 44__wakeup() called 45array(1) { 46 [0]=> 47 object(Unserialize)#8 (2) { 48 ["data"]=> 49 array(0) { 50 } 51 ["unserialized"]=> 52 bool(true) 53 } 54} 55__unserialize() called 56array(1) { 57 [0]=> 58 object(Wakeup)#7 (2) { 59 ["data"]=> 60 array(1) { 61 [0]=> 62 object(Unserialize)#8 (2) { 63 ["data"]=> 64 array(0) { 65 } 66 ["unserialized"]=> 67 bool(true) 68 } 69 } 70 ["woken_up"]=> 71 bool(true) 72 } 73} 74__wakeup() called 75array(1) { 76 [0]=> 77 object(Unserialize)#6 (2) { 78 ["data"]=> 79 array(1) { 80 [0]=> 81 object(Wakeup)#7 (2) { 82 ["data"]=> 83 array(1) { 84 [0]=> 85 object(Unserialize)#8 (2) { 86 ["data"]=> 87 array(0) { 88 } 89 ["unserialized"]=> 90 bool(true) 91 } 92 } 93 ["woken_up"]=> 94 bool(true) 95 } 96 } 97 ["unserialized"]=> 98 bool(true) 99 } 100} 101object(Wakeup)#5 (2) { 102 ["data"]=> 103 array(1) { 104 [0]=> 105 object(Unserialize)#6 (2) { 106 ["data"]=> 107 array(1) { 108 [0]=> 109 object(Wakeup)#7 (2) { 110 ["data"]=> 111 array(1) { 112 [0]=> 113 object(Unserialize)#8 (2) { 114 ["data"]=> 115 array(0) { 116 } 117 ["unserialized"]=> 118 bool(true) 119 } 120 } 121 ["woken_up"]=> 122 bool(true) 123 } 124 } 125 ["unserialized"]=> 126 bool(true) 127 } 128 } 129 ["woken_up"]=> 130 bool(true) 131} 132