1--TEST-- 2Object serialization / unserialization: references amongst properties 3--INI-- 4error_reporting = E_ALL & ~E_STRICT 5--FILE-- 6<?php 7/* Prototype : proto string serialize(mixed variable) 8 * Description: Returns a string representation of variable (which can later be unserialized) 9 * Source code: ext/standard/var.c 10 * Alias to functions: 11 */ 12/* Prototype : proto mixed unserialize(string variable_representation) 13 * Description: Takes a string representation of variable and recreates it 14 * Source code: ext/standard/var.c 15 * Alias to functions: 16 */ 17 18function check(&$obj) { 19 var_dump($obj); 20 $ser = serialize($obj); 21 var_dump($ser); 22 23 $uobj = unserialize($ser); 24 var_dump($uobj); 25 $uobj->a = "obj->a.changed"; 26 var_dump($uobj); 27 $uobj->b = "obj->b.changed"; 28 var_dump($uobj); 29 $uobj->c = "obj->c.changed"; 30 var_dump($uobj); 31} 32 33echo "\n\n--- a refs b:\n"; 34$obj = new stdClass; 35$obj->b = 1; 36$obj->a = &$obj->b; 37$obj->c = 1; 38check($obj); 39 40echo "\n\n--- a refs c:\n"; 41$obj = new stdClass; 42$obj->c = 1; 43$obj->a = &$obj->c; 44$obj->b = 1; 45check($obj); 46 47echo "\n\n--- b refs a:\n"; 48$obj = new stdClass; 49$obj->a = 1; 50$obj->b = &$obj->a; 51$obj->c = 1; 52check($obj); 53 54echo "\n\n--- b refs c:\n"; 55$obj = new stdClass; 56$obj->a = 1; 57$obj->c = 1; 58$obj->b = &$obj->c; 59check($obj); 60 61echo "\n\n--- c refs a:\n"; 62$obj = new stdClass; 63$obj->a = 1; 64$obj->b = 1; 65$obj->c = &$obj->a; 66check($obj); 67 68echo "\n\n--- c refs b:\n"; 69$obj = new stdClass; 70$obj->a = 1; 71$obj->b = 1; 72$obj->c = &$obj->b; 73check($obj); 74 75echo "\n\n--- a,b refs c:\n"; 76$obj = new stdClass; 77$obj->c = 1; 78$obj->a = &$obj->c; 79$obj->b = &$obj->c; 80check($obj); 81 82echo "\n\n--- a,c refs b:\n"; 83$obj = new stdClass; 84$obj->b = 1; 85$obj->a = &$obj->b; 86$obj->c = &$obj->b; 87check($obj); 88 89echo "\n\n--- b,c refs a:\n"; 90$obj = new stdClass; 91$obj->a = 1; 92$obj->b = &$obj->a; 93$obj->c = &$obj->a; 94check($obj); 95 96echo "Done"; 97?> 98--EXPECTF-- 99--- a refs b: 100object(stdClass)#%d (3) { 101 ["b"]=> 102 &int(1) 103 ["a"]=> 104 &int(1) 105 ["c"]=> 106 int(1) 107} 108string(55) "O:8:"stdClass":3:{s:1:"b";i:1;s:1:"a";R:2;s:1:"c";i:1;}" 109object(stdClass)#%d (3) { 110 ["b"]=> 111 &int(1) 112 ["a"]=> 113 &int(1) 114 ["c"]=> 115 int(1) 116} 117object(stdClass)#%d (3) { 118 ["b"]=> 119 &string(14) "obj->a.changed" 120 ["a"]=> 121 &string(14) "obj->a.changed" 122 ["c"]=> 123 int(1) 124} 125object(stdClass)#%d (3) { 126 ["b"]=> 127 &string(14) "obj->b.changed" 128 ["a"]=> 129 &string(14) "obj->b.changed" 130 ["c"]=> 131 int(1) 132} 133object(stdClass)#%d (3) { 134 ["b"]=> 135 &string(14) "obj->b.changed" 136 ["a"]=> 137 &string(14) "obj->b.changed" 138 ["c"]=> 139 string(14) "obj->c.changed" 140} 141 142 143--- a refs c: 144object(stdClass)#%d (3) { 145 ["c"]=> 146 &int(1) 147 ["a"]=> 148 &int(1) 149 ["b"]=> 150 int(1) 151} 152string(55) "O:8:"stdClass":3:{s:1:"c";i:1;s:1:"a";R:2;s:1:"b";i:1;}" 153object(stdClass)#%d (3) { 154 ["c"]=> 155 &int(1) 156 ["a"]=> 157 &int(1) 158 ["b"]=> 159 int(1) 160} 161object(stdClass)#%d (3) { 162 ["c"]=> 163 &string(14) "obj->a.changed" 164 ["a"]=> 165 &string(14) "obj->a.changed" 166 ["b"]=> 167 int(1) 168} 169object(stdClass)#%d (3) { 170 ["c"]=> 171 &string(14) "obj->a.changed" 172 ["a"]=> 173 &string(14) "obj->a.changed" 174 ["b"]=> 175 string(14) "obj->b.changed" 176} 177object(stdClass)#%d (3) { 178 ["c"]=> 179 &string(14) "obj->c.changed" 180 ["a"]=> 181 &string(14) "obj->c.changed" 182 ["b"]=> 183 string(14) "obj->b.changed" 184} 185 186 187--- b refs a: 188object(stdClass)#%d (3) { 189 ["a"]=> 190 &int(1) 191 ["b"]=> 192 &int(1) 193 ["c"]=> 194 int(1) 195} 196string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";i:1;}" 197object(stdClass)#%d (3) { 198 ["a"]=> 199 &int(1) 200 ["b"]=> 201 &int(1) 202 ["c"]=> 203 int(1) 204} 205object(stdClass)#%d (3) { 206 ["a"]=> 207 &string(14) "obj->a.changed" 208 ["b"]=> 209 &string(14) "obj->a.changed" 210 ["c"]=> 211 int(1) 212} 213object(stdClass)#%d (3) { 214 ["a"]=> 215 &string(14) "obj->b.changed" 216 ["b"]=> 217 &string(14) "obj->b.changed" 218 ["c"]=> 219 int(1) 220} 221object(stdClass)#%d (3) { 222 ["a"]=> 223 &string(14) "obj->b.changed" 224 ["b"]=> 225 &string(14) "obj->b.changed" 226 ["c"]=> 227 string(14) "obj->c.changed" 228} 229 230 231--- b refs c: 232object(stdClass)#%d (3) { 233 ["a"]=> 234 int(1) 235 ["c"]=> 236 &int(1) 237 ["b"]=> 238 &int(1) 239} 240string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"c";i:1;s:1:"b";R:3;}" 241object(stdClass)#%d (3) { 242 ["a"]=> 243 int(1) 244 ["c"]=> 245 &int(1) 246 ["b"]=> 247 &int(1) 248} 249object(stdClass)#%d (3) { 250 ["a"]=> 251 string(14) "obj->a.changed" 252 ["c"]=> 253 &int(1) 254 ["b"]=> 255 &int(1) 256} 257object(stdClass)#%d (3) { 258 ["a"]=> 259 string(14) "obj->a.changed" 260 ["c"]=> 261 &string(14) "obj->b.changed" 262 ["b"]=> 263 &string(14) "obj->b.changed" 264} 265object(stdClass)#%d (3) { 266 ["a"]=> 267 string(14) "obj->a.changed" 268 ["c"]=> 269 &string(14) "obj->c.changed" 270 ["b"]=> 271 &string(14) "obj->c.changed" 272} 273 274 275--- c refs a: 276object(stdClass)#%d (3) { 277 ["a"]=> 278 &int(1) 279 ["b"]=> 280 int(1) 281 ["c"]=> 282 &int(1) 283} 284string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";R:2;}" 285object(stdClass)#%d (3) { 286 ["a"]=> 287 &int(1) 288 ["b"]=> 289 int(1) 290 ["c"]=> 291 &int(1) 292} 293object(stdClass)#%d (3) { 294 ["a"]=> 295 &string(14) "obj->a.changed" 296 ["b"]=> 297 int(1) 298 ["c"]=> 299 &string(14) "obj->a.changed" 300} 301object(stdClass)#%d (3) { 302 ["a"]=> 303 &string(14) "obj->a.changed" 304 ["b"]=> 305 string(14) "obj->b.changed" 306 ["c"]=> 307 &string(14) "obj->a.changed" 308} 309object(stdClass)#%d (3) { 310 ["a"]=> 311 &string(14) "obj->c.changed" 312 ["b"]=> 313 string(14) "obj->b.changed" 314 ["c"]=> 315 &string(14) "obj->c.changed" 316} 317 318 319--- c refs b: 320object(stdClass)#%d (3) { 321 ["a"]=> 322 int(1) 323 ["b"]=> 324 &int(1) 325 ["c"]=> 326 &int(1) 327} 328string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";i:1;s:1:"c";R:3;}" 329object(stdClass)#%d (3) { 330 ["a"]=> 331 int(1) 332 ["b"]=> 333 &int(1) 334 ["c"]=> 335 &int(1) 336} 337object(stdClass)#%d (3) { 338 ["a"]=> 339 string(14) "obj->a.changed" 340 ["b"]=> 341 &int(1) 342 ["c"]=> 343 &int(1) 344} 345object(stdClass)#%d (3) { 346 ["a"]=> 347 string(14) "obj->a.changed" 348 ["b"]=> 349 &string(14) "obj->b.changed" 350 ["c"]=> 351 &string(14) "obj->b.changed" 352} 353object(stdClass)#%d (3) { 354 ["a"]=> 355 string(14) "obj->a.changed" 356 ["b"]=> 357 &string(14) "obj->c.changed" 358 ["c"]=> 359 &string(14) "obj->c.changed" 360} 361 362 363--- a,b refs c: 364object(stdClass)#%d (3) { 365 ["c"]=> 366 &int(1) 367 ["a"]=> 368 &int(1) 369 ["b"]=> 370 &int(1) 371} 372string(55) "O:8:"stdClass":3:{s:1:"c";i:1;s:1:"a";R:2;s:1:"b";R:2;}" 373object(stdClass)#%d (3) { 374 ["c"]=> 375 &int(1) 376 ["a"]=> 377 &int(1) 378 ["b"]=> 379 &int(1) 380} 381object(stdClass)#%d (3) { 382 ["c"]=> 383 &string(14) "obj->a.changed" 384 ["a"]=> 385 &string(14) "obj->a.changed" 386 ["b"]=> 387 &string(14) "obj->a.changed" 388} 389object(stdClass)#%d (3) { 390 ["c"]=> 391 &string(14) "obj->b.changed" 392 ["a"]=> 393 &string(14) "obj->b.changed" 394 ["b"]=> 395 &string(14) "obj->b.changed" 396} 397object(stdClass)#%d (3) { 398 ["c"]=> 399 &string(14) "obj->c.changed" 400 ["a"]=> 401 &string(14) "obj->c.changed" 402 ["b"]=> 403 &string(14) "obj->c.changed" 404} 405 406 407--- a,c refs b: 408object(stdClass)#%d (3) { 409 ["b"]=> 410 &int(1) 411 ["a"]=> 412 &int(1) 413 ["c"]=> 414 &int(1) 415} 416string(55) "O:8:"stdClass":3:{s:1:"b";i:1;s:1:"a";R:2;s:1:"c";R:2;}" 417object(stdClass)#%d (3) { 418 ["b"]=> 419 &int(1) 420 ["a"]=> 421 &int(1) 422 ["c"]=> 423 &int(1) 424} 425object(stdClass)#%d (3) { 426 ["b"]=> 427 &string(14) "obj->a.changed" 428 ["a"]=> 429 &string(14) "obj->a.changed" 430 ["c"]=> 431 &string(14) "obj->a.changed" 432} 433object(stdClass)#%d (3) { 434 ["b"]=> 435 &string(14) "obj->b.changed" 436 ["a"]=> 437 &string(14) "obj->b.changed" 438 ["c"]=> 439 &string(14) "obj->b.changed" 440} 441object(stdClass)#%d (3) { 442 ["b"]=> 443 &string(14) "obj->c.changed" 444 ["a"]=> 445 &string(14) "obj->c.changed" 446 ["c"]=> 447 &string(14) "obj->c.changed" 448} 449 450 451--- b,c refs a: 452object(stdClass)#%d (3) { 453 ["a"]=> 454 &int(1) 455 ["b"]=> 456 &int(1) 457 ["c"]=> 458 &int(1) 459} 460string(55) "O:8:"stdClass":3:{s:1:"a";i:1;s:1:"b";R:2;s:1:"c";R:2;}" 461object(stdClass)#%d (3) { 462 ["a"]=> 463 &int(1) 464 ["b"]=> 465 &int(1) 466 ["c"]=> 467 &int(1) 468} 469object(stdClass)#%d (3) { 470 ["a"]=> 471 &string(14) "obj->a.changed" 472 ["b"]=> 473 &string(14) "obj->a.changed" 474 ["c"]=> 475 &string(14) "obj->a.changed" 476} 477object(stdClass)#%d (3) { 478 ["a"]=> 479 &string(14) "obj->b.changed" 480 ["b"]=> 481 &string(14) "obj->b.changed" 482 ["c"]=> 483 &string(14) "obj->b.changed" 484} 485object(stdClass)#%d (3) { 486 ["a"]=> 487 &string(14) "obj->c.changed" 488 ["b"]=> 489 &string(14) "obj->c.changed" 490 ["c"]=> 491 &string(14) "obj->c.changed" 492} 493Done 494