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