1--TEST-- 2Object serialization / unserialization: references to external values 3--FILE-- 4<?php 5/* Prototype : proto string serialize(mixed variable) 6 * Description: Returns a string representation of variable (which can later be unserialized) 7 * Source code: ext/standard/var.c 8 * Alias to functions: 9 */ 10/* Prototype : proto mixed unserialize(string variable_representation) 11 * Description: Takes a string representation of variable and recreates it 12 * Source code: ext/standard/var.c 13 * Alias to functions: 14 */ 15 16function check(&$obj) { 17 var_dump($obj); 18 $ser = serialize($obj); 19 var_dump($ser); 20 21 $uobj = unserialize($ser); 22 var_dump($uobj); 23 $uobj->a = "obj->a.changed"; 24 var_dump($uobj); 25 $uobj->b = "obj->b.changed"; 26 var_dump($uobj); 27 $uobj->c = "obj->c.changed"; 28 var_dump($uobj); 29} 30 31echo "\n\n--- a refs external:\n"; 32$ext = 1; 33$obj = new stdClass; 34$obj->a = &$ext; 35$obj->b = 1; 36$obj->c = 1; 37check($obj); 38 39echo "\n\n--- b refs external:\n"; 40$ext = 1; 41$obj = new stdClass; 42$obj->a = 1; 43$obj->b = &$ext; 44$obj->c = 1; 45check($obj); 46 47echo "\n\n--- c refs external:\n"; 48$ext = 1; 49$obj = new stdClass; 50$obj->a = 1; 51$obj->b = 1; 52$obj->c = &$ext; 53check($obj); 54 55echo "\n\n--- a,b ref external:\n"; 56$ext = 1; 57$obj = new stdClass; 58$obj->a = &$ext; 59$obj->b = &$ext; 60$obj->c = 1; 61check($obj); 62 63echo "\n\n--- a,b,c ref external:\n"; 64$ext = 1; 65$obj = new stdClass; 66$obj->a = &$ext; 67$obj->b = &$ext; 68$obj->c = &$ext; 69check($obj); 70 71echo "Done"; 72?> 73--EXPECTF-- 74--- a refs external: 75object(stdClass)#%d (3) { 76 ["a"]=> 77 &int(1) 78 ["b"]=> 79 int(1) 80 ["c"]=> 81 int(1) 82} 83string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";i:1;}" 84object(stdClass)#%d (3) { 85 ["a"]=> 86 int(1) 87 ["b"]=> 88 int(1) 89 ["c"]=> 90 int(1) 91} 92object(stdClass)#%d (3) { 93 ["a"]=> 94 string(14) "obj->a.changed" 95 ["b"]=> 96 int(1) 97 ["c"]=> 98 int(1) 99} 100object(stdClass)#%d (3) { 101 ["a"]=> 102 string(14) "obj->a.changed" 103 ["b"]=> 104 string(14) "obj->b.changed" 105 ["c"]=> 106 int(1) 107} 108object(stdClass)#%d (3) { 109 ["a"]=> 110 string(14) "obj->a.changed" 111 ["b"]=> 112 string(14) "obj->b.changed" 113 ["c"]=> 114 string(14) "obj->c.changed" 115} 116 117 118--- b refs external: 119object(stdClass)#%d (3) { 120 ["a"]=> 121 int(1) 122 ["b"]=> 123 &int(1) 124 ["c"]=> 125 int(1) 126} 127string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";i:1;}" 128object(stdClass)#%d (3) { 129 ["a"]=> 130 int(1) 131 ["b"]=> 132 int(1) 133 ["c"]=> 134 int(1) 135} 136object(stdClass)#%d (3) { 137 ["a"]=> 138 string(14) "obj->a.changed" 139 ["b"]=> 140 int(1) 141 ["c"]=> 142 int(1) 143} 144object(stdClass)#%d (3) { 145 ["a"]=> 146 string(14) "obj->a.changed" 147 ["b"]=> 148 string(14) "obj->b.changed" 149 ["c"]=> 150 int(1) 151} 152object(stdClass)#%d (3) { 153 ["a"]=> 154 string(14) "obj->a.changed" 155 ["b"]=> 156 string(14) "obj->b.changed" 157 ["c"]=> 158 string(14) "obj->c.changed" 159} 160 161 162--- c refs external: 163object(stdClass)#%d (3) { 164 ["a"]=> 165 int(1) 166 ["b"]=> 167 int(1) 168 ["c"]=> 169 &int(1) 170} 171string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";i:1;}" 172object(stdClass)#%d (3) { 173 ["a"]=> 174 int(1) 175 ["b"]=> 176 int(1) 177 ["c"]=> 178 int(1) 179} 180object(stdClass)#%d (3) { 181 ["a"]=> 182 string(14) "obj->a.changed" 183 ["b"]=> 184 int(1) 185 ["c"]=> 186 int(1) 187} 188object(stdClass)#%d (3) { 189 ["a"]=> 190 string(14) "obj->a.changed" 191 ["b"]=> 192 string(14) "obj->b.changed" 193 ["c"]=> 194 int(1) 195} 196object(stdClass)#%d (3) { 197 ["a"]=> 198 string(14) "obj->a.changed" 199 ["b"]=> 200 string(14) "obj->b.changed" 201 ["c"]=> 202 string(14) "obj->c.changed" 203} 204 205 206--- a,b ref external: 207object(stdClass)#%d (3) { 208 ["a"]=> 209 &int(1) 210 ["b"]=> 211 &int(1) 212 ["c"]=> 213 int(1) 214} 215string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";i:1;}" 216object(stdClass)#%d (3) { 217 ["a"]=> 218 &int(1) 219 ["b"]=> 220 &int(1) 221 ["c"]=> 222 int(1) 223} 224object(stdClass)#%d (3) { 225 ["a"]=> 226 &string(14) "obj->a.changed" 227 ["b"]=> 228 &string(14) "obj->a.changed" 229 ["c"]=> 230 int(1) 231} 232object(stdClass)#%d (3) { 233 ["a"]=> 234 &string(14) "obj->b.changed" 235 ["b"]=> 236 &string(14) "obj->b.changed" 237 ["c"]=> 238 int(1) 239} 240object(stdClass)#%d (3) { 241 ["a"]=> 242 &string(14) "obj->b.changed" 243 ["b"]=> 244 &string(14) "obj->b.changed" 245 ["c"]=> 246 string(14) "obj->c.changed" 247} 248 249 250--- a,b,c ref external: 251object(stdClass)#%d (3) { 252 ["a"]=> 253 &int(1) 254 ["b"]=> 255 &int(1) 256 ["c"]=> 257 &int(1) 258} 259string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";R:2;}" 260object(stdClass)#%d (3) { 261 ["a"]=> 262 &int(1) 263 ["b"]=> 264 &int(1) 265 ["c"]=> 266 &int(1) 267} 268object(stdClass)#%d (3) { 269 ["a"]=> 270 &string(14) "obj->a.changed" 271 ["b"]=> 272 &string(14) "obj->a.changed" 273 ["c"]=> 274 &string(14) "obj->a.changed" 275} 276object(stdClass)#%d (3) { 277 ["a"]=> 278 &string(14) "obj->b.changed" 279 ["b"]=> 280 &string(14) "obj->b.changed" 281 ["c"]=> 282 &string(14) "obj->b.changed" 283} 284object(stdClass)#%d (3) { 285 ["a"]=> 286 &string(14) "obj->c.changed" 287 ["b"]=> 288 &string(14) "obj->c.changed" 289 ["c"]=> 290 &string(14) "obj->c.changed" 291} 292Done 293