1--TEST-- 2SPL: ArrayObject::exchangeArray($this) 3--FILE-- 4<?php 5 6class ArrayIteratorEx extends ArrayIterator 7{ 8 public $pub2 = 1; 9 protected $pro2 = 2; 10 private $pri2 = 3; 11 12 function __construct($ar, $flags = 0) 13 { 14 echo __METHOD__ . "()\n"; 15 parent::__construct($ar, $flags); 16 $this->imp2 = 4; 17 } 18 19 function dump() 20 { 21 echo __METHOD__ . "()\n"; 22 var_dump(array('Flags'=>$this->getFlags() 23 ,'OVars'=>get_object_vars($this) 24 ,'$this'=>$this)); 25 } 26 27 function setFlags($flags) 28 { 29 echo __METHOD__ . "($flags)\n"; 30 ArrayIterator::setFlags($flags); 31 } 32} 33 34class ArrayObjectEx extends ArrayObject 35{ 36 public $pub1 = 1; 37 protected $pro1 = 2; 38 private $pri1 = 3; 39 40 function __construct($ar = array(), $flags = 0) 41 { 42 echo __METHOD__ . "()\n"; 43 parent::__construct($ar, $flags); 44 $this->imp1 = 4; 45 } 46 47 function exchange() 48 { 49 echo __METHOD__ . "()\n"; 50 $this->exchangeArray($this); 51 } 52 53 function dump() 54 { 55 echo __METHOD__ . "()\n"; 56 var_dump(array('Flags'=>$this->getFlags() 57 ,'OVars'=>get_object_vars($this) 58 ,'$this'=>$this)); 59 } 60 61 function show() 62 { 63 echo __METHOD__ . "()\n"; 64 foreach($this as $n => $v) 65 { 66 var_dump(array($n => $v)); 67 } 68 } 69 70 function setFlags($flags) 71 { 72 echo __METHOD__ . "($flags)\n"; 73 ArrayObject::setFlags($flags); 74 } 75 76 function getIterator() 77 { 78 echo __METHOD__ . "()\n"; 79 $it = new ArrayIteratorEx($this, $this->getFlags()); 80 $it->dyn2 = 5; 81 $it->dump(); 82 return $it; 83 } 84} 85 86function check($obj, $flags) 87{ 88 echo "===CHECK===\n"; 89 90 $obj->setFlags($flags); 91 $obj->dump(); 92 $obj->show(); 93 94 echo "===FOREACH===\n"; 95 96 $it = $obj->getIterator(); 97 foreach($it as $n => $v) 98 { 99 var_dump(array($n => $v)); 100 } 101 102 echo "===PROPERTY===\n"; 103 104 var_dump($obj->pub1); 105 var_dump(isset($obj->a)); 106 $obj->setFlags($flags | 2); 107 var_dump($obj->pub1); 108 var_dump(isset($obj->a)); 109 110 var_dump($it->pub2); 111 var_dump(isset($it->pub1)); 112 $it->setFlags($flags | 2); 113 var_dump($it->pub2); 114 var_dump(isset($it->pub1)); 115} 116 117$obj = new ArrayObjectEx(array(0=>1,'a'=>25, 'pub1'=>42), 0); 118$obj->dyn1 = 5; 119 120check($obj, 0); 121check($obj, 1); 122 123echo "#####EXCHANGE#####\n"; 124 125$obj->exchange(); 126 127check($obj, 0); 128check($obj, 1); 129 130?> 131===DONE=== 132<?php exit(0); ?> 133--EXPECTF-- 134ArrayObjectEx::__construct() 135===CHECK=== 136ArrayObjectEx::setFlags(0) 137ArrayObjectEx::dump() 138array(3) { 139 ["Flags"]=> 140 int(0) 141 ["OVars"]=> 142 array(3) { 143 [0]=> 144 int(1) 145 ["a"]=> 146 int(25) 147 ["pub1"]=> 148 int(42) 149 } 150 ["$this"]=> 151 object(ArrayObjectEx)#%d (6) { 152 ["pub1"]=> 153 int(1) 154 ["pro1":protected]=> 155 int(2) 156 ["pri1":"ArrayObjectEx":private]=> 157 int(3) 158 ["imp1"]=> 159 int(4) 160 ["dyn1"]=> 161 int(5) 162 ["storage":"ArrayObject":private]=> 163 array(3) { 164 [0]=> 165 int(1) 166 ["a"]=> 167 int(25) 168 ["pub1"]=> 169 int(42) 170 } 171 } 172} 173ArrayObjectEx::show() 174ArrayObjectEx::getIterator() 175ArrayIteratorEx::__construct() 176ArrayIteratorEx::dump() 177array(3) { 178 ["Flags"]=> 179 int(0) 180 ["OVars"]=> 181 array(3) { 182 [0]=> 183 int(1) 184 ["a"]=> 185 int(25) 186 ["pub1"]=> 187 int(42) 188 } 189 ["$this"]=> 190 object(ArrayIteratorEx)#%d (6) { 191 ["pub2"]=> 192 int(1) 193 ["pro2":protected]=> 194 int(2) 195 ["pri2":"ArrayIteratorEx":private]=> 196 int(3) 197 ["imp2"]=> 198 int(4) 199 ["dyn2"]=> 200 int(5) 201 ["storage":"ArrayIterator":private]=> 202 object(ArrayObjectEx)#%d (6) { 203 ["pub1"]=> 204 int(1) 205 ["pro1":protected]=> 206 int(2) 207 ["pri1":"ArrayObjectEx":private]=> 208 int(3) 209 ["imp1"]=> 210 int(4) 211 ["dyn1"]=> 212 int(5) 213 ["storage":"ArrayObject":private]=> 214 array(3) { 215 [0]=> 216 int(1) 217 ["a"]=> 218 int(25) 219 ["pub1"]=> 220 int(42) 221 } 222 } 223 } 224} 225array(1) { 226 [0]=> 227 int(1) 228} 229array(1) { 230 ["a"]=> 231 int(25) 232} 233array(1) { 234 ["pub1"]=> 235 int(42) 236} 237===FOREACH=== 238ArrayObjectEx::getIterator() 239ArrayIteratorEx::__construct() 240ArrayIteratorEx::dump() 241array(3) { 242 ["Flags"]=> 243 int(0) 244 ["OVars"]=> 245 array(3) { 246 [0]=> 247 int(1) 248 ["a"]=> 249 int(25) 250 ["pub1"]=> 251 int(42) 252 } 253 ["$this"]=> 254 object(ArrayIteratorEx)#%d (6) { 255 ["pub2"]=> 256 int(1) 257 ["pro2":protected]=> 258 int(2) 259 ["pri2":"ArrayIteratorEx":private]=> 260 int(3) 261 ["imp2"]=> 262 int(4) 263 ["dyn2"]=> 264 int(5) 265 ["storage":"ArrayIterator":private]=> 266 object(ArrayObjectEx)#%d (6) { 267 ["pub1"]=> 268 int(1) 269 ["pro1":protected]=> 270 int(2) 271 ["pri1":"ArrayObjectEx":private]=> 272 int(3) 273 ["imp1"]=> 274 int(4) 275 ["dyn1"]=> 276 int(5) 277 ["storage":"ArrayObject":private]=> 278 array(3) { 279 [0]=> 280 int(1) 281 ["a"]=> 282 int(25) 283 ["pub1"]=> 284 int(42) 285 } 286 } 287 } 288} 289array(1) { 290 [0]=> 291 int(1) 292} 293array(1) { 294 ["a"]=> 295 int(25) 296} 297array(1) { 298 ["pub1"]=> 299 int(42) 300} 301===PROPERTY=== 302int(1) 303bool(false) 304ArrayObjectEx::setFlags(2) 305int(1) 306bool(true) 307int(1) 308bool(false) 309ArrayIteratorEx::setFlags(2) 310int(1) 311bool(true) 312===CHECK=== 313ArrayObjectEx::setFlags(1) 314ArrayObjectEx::dump() 315array(3) { 316 ["Flags"]=> 317 int(1) 318 ["OVars"]=> 319 array(5) { 320 ["pub1"]=> 321 int(1) 322 ["pro1"]=> 323 int(2) 324 ["pri1"]=> 325 int(3) 326 ["imp1"]=> 327 int(4) 328 ["dyn1"]=> 329 int(5) 330 } 331 ["$this"]=> 332 object(ArrayObjectEx)#%d (6) { 333 ["pub1"]=> 334 int(1) 335 ["pro1":protected]=> 336 int(2) 337 ["pri1":"ArrayObjectEx":private]=> 338 int(3) 339 ["imp1"]=> 340 int(4) 341 ["dyn1"]=> 342 int(5) 343 ["storage":"ArrayObject":private]=> 344 array(3) { 345 [0]=> 346 int(1) 347 ["a"]=> 348 int(25) 349 ["pub1"]=> 350 int(42) 351 } 352 } 353} 354ArrayObjectEx::show() 355ArrayObjectEx::getIterator() 356ArrayIteratorEx::__construct() 357ArrayIteratorEx::dump() 358array(3) { 359 ["Flags"]=> 360 int(1) 361 ["OVars"]=> 362 array(5) { 363 ["pub2"]=> 364 int(1) 365 ["pro2"]=> 366 int(2) 367 ["pri2"]=> 368 int(3) 369 ["imp2"]=> 370 int(4) 371 ["dyn2"]=> 372 int(5) 373 } 374 ["$this"]=> 375 object(ArrayIteratorEx)#%d (6) { 376 ["pub2"]=> 377 int(1) 378 ["pro2":protected]=> 379 int(2) 380 ["pri2":"ArrayIteratorEx":private]=> 381 int(3) 382 ["imp2"]=> 383 int(4) 384 ["dyn2"]=> 385 int(5) 386 ["storage":"ArrayIterator":private]=> 387 object(ArrayObjectEx)#%d (6) { 388 ["pub1"]=> 389 int(1) 390 ["pro1":protected]=> 391 int(2) 392 ["pri1":"ArrayObjectEx":private]=> 393 int(3) 394 ["imp1"]=> 395 int(4) 396 ["dyn1"]=> 397 int(5) 398 ["storage":"ArrayObject":private]=> 399 array(3) { 400 [0]=> 401 int(1) 402 ["a"]=> 403 int(25) 404 ["pub1"]=> 405 int(42) 406 } 407 } 408 } 409} 410array(1) { 411 [0]=> 412 int(1) 413} 414array(1) { 415 ["a"]=> 416 int(25) 417} 418array(1) { 419 ["pub1"]=> 420 int(42) 421} 422===FOREACH=== 423ArrayObjectEx::getIterator() 424ArrayIteratorEx::__construct() 425ArrayIteratorEx::dump() 426array(3) { 427 ["Flags"]=> 428 int(1) 429 ["OVars"]=> 430 array(5) { 431 ["pub2"]=> 432 int(1) 433 ["pro2"]=> 434 int(2) 435 ["pri2"]=> 436 int(3) 437 ["imp2"]=> 438 int(4) 439 ["dyn2"]=> 440 int(5) 441 } 442 ["$this"]=> 443 object(ArrayIteratorEx)#%d (6) { 444 ["pub2"]=> 445 int(1) 446 ["pro2":protected]=> 447 int(2) 448 ["pri2":"ArrayIteratorEx":private]=> 449 int(3) 450 ["imp2"]=> 451 int(4) 452 ["dyn2"]=> 453 int(5) 454 ["storage":"ArrayIterator":private]=> 455 object(ArrayObjectEx)#%d (6) { 456 ["pub1"]=> 457 int(1) 458 ["pro1":protected]=> 459 int(2) 460 ["pri1":"ArrayObjectEx":private]=> 461 int(3) 462 ["imp1"]=> 463 int(4) 464 ["dyn1"]=> 465 int(5) 466 ["storage":"ArrayObject":private]=> 467 array(3) { 468 [0]=> 469 int(1) 470 ["a"]=> 471 int(25) 472 ["pub1"]=> 473 int(42) 474 } 475 } 476 } 477} 478array(1) { 479 [0]=> 480 int(1) 481} 482array(1) { 483 ["a"]=> 484 int(25) 485} 486array(1) { 487 ["pub1"]=> 488 int(42) 489} 490===PROPERTY=== 491int(1) 492bool(false) 493ArrayObjectEx::setFlags(3) 494int(1) 495bool(true) 496int(1) 497bool(false) 498ArrayIteratorEx::setFlags(3) 499int(1) 500bool(true) 501#####EXCHANGE##### 502ArrayObjectEx::exchange() 503===CHECK=== 504ArrayObjectEx::setFlags(0) 505ArrayObjectEx::dump() 506array(3) { 507 ["Flags"]=> 508 int(0) 509 ["OVars"]=> 510 array(5) { 511 ["pub1"]=> 512 int(1) 513 ["pro1"]=> 514 int(2) 515 ["pri1"]=> 516 int(3) 517 ["imp1"]=> 518 int(4) 519 ["dyn1"]=> 520 int(5) 521 } 522 ["$this"]=> 523 object(ArrayObjectEx)#%d (5) { 524 ["pub1"]=> 525 int(1) 526 ["pro1":protected]=> 527 int(2) 528 ["pri1":"ArrayObjectEx":private]=> 529 int(3) 530 ["imp1"]=> 531 int(4) 532 ["dyn1"]=> 533 int(5) 534 } 535} 536ArrayObjectEx::show() 537ArrayObjectEx::getIterator() 538ArrayIteratorEx::__construct() 539ArrayIteratorEx::dump() 540array(3) { 541 ["Flags"]=> 542 int(0) 543 ["OVars"]=> 544 array(4) { 545 ["pub1"]=> 546 int(1) 547 ["pro1"]=> 548 int(2) 549 ["imp1"]=> 550 int(4) 551 ["dyn1"]=> 552 int(5) 553 } 554 ["$this"]=> 555 object(ArrayIteratorEx)#%d (6) { 556 ["pub2"]=> 557 int(1) 558 ["pro2":protected]=> 559 int(2) 560 ["pri2":"ArrayIteratorEx":private]=> 561 int(3) 562 ["imp2"]=> 563 int(4) 564 ["dyn2"]=> 565 int(5) 566 ["storage":"ArrayIterator":private]=> 567 object(ArrayObjectEx)#%d (5) { 568 ["pub1"]=> 569 int(1) 570 ["pro1":protected]=> 571 int(2) 572 ["pri1":"ArrayObjectEx":private]=> 573 int(3) 574 ["imp1"]=> 575 int(4) 576 ["dyn1"]=> 577 int(5) 578 } 579 } 580} 581array(1) { 582 ["pub1"]=> 583 int(1) 584} 585array(1) { 586 ["imp1"]=> 587 int(4) 588} 589array(1) { 590 ["dyn1"]=> 591 int(5) 592} 593===FOREACH=== 594ArrayObjectEx::getIterator() 595ArrayIteratorEx::__construct() 596ArrayIteratorEx::dump() 597array(3) { 598 ["Flags"]=> 599 int(0) 600 ["OVars"]=> 601 array(4) { 602 ["pub1"]=> 603 int(1) 604 ["pro1"]=> 605 int(2) 606 ["imp1"]=> 607 int(4) 608 ["dyn1"]=> 609 int(5) 610 } 611 ["$this"]=> 612 object(ArrayIteratorEx)#%d (6) { 613 ["pub2"]=> 614 int(1) 615 ["pro2":protected]=> 616 int(2) 617 ["pri2":"ArrayIteratorEx":private]=> 618 int(3) 619 ["imp2"]=> 620 int(4) 621 ["dyn2"]=> 622 int(5) 623 ["storage":"ArrayIterator":private]=> 624 object(ArrayObjectEx)#%d (5) { 625 ["pub1"]=> 626 int(1) 627 ["pro1":protected]=> 628 int(2) 629 ["pri1":"ArrayObjectEx":private]=> 630 int(3) 631 ["imp1"]=> 632 int(4) 633 ["dyn1"]=> 634 int(5) 635 } 636 } 637} 638array(1) { 639 ["pub1"]=> 640 int(1) 641} 642array(1) { 643 ["imp1"]=> 644 int(4) 645} 646array(1) { 647 ["dyn1"]=> 648 int(5) 649} 650===PROPERTY=== 651int(1) 652bool(false) 653ArrayObjectEx::setFlags(2) 654int(1) 655bool(false) 656int(1) 657bool(false) 658ArrayIteratorEx::setFlags(2) 659int(1) 660bool(true) 661===CHECK=== 662ArrayObjectEx::setFlags(1) 663ArrayObjectEx::dump() 664array(3) { 665 ["Flags"]=> 666 int(1) 667 ["OVars"]=> 668 array(5) { 669 ["pub1"]=> 670 int(1) 671 ["pro1"]=> 672 int(2) 673 ["pri1"]=> 674 int(3) 675 ["imp1"]=> 676 int(4) 677 ["dyn1"]=> 678 int(5) 679 } 680 ["$this"]=> 681 object(ArrayObjectEx)#%d (5) { 682 ["pub1"]=> 683 int(1) 684 ["pro1":protected]=> 685 int(2) 686 ["pri1":"ArrayObjectEx":private]=> 687 int(3) 688 ["imp1"]=> 689 int(4) 690 ["dyn1"]=> 691 int(5) 692 } 693} 694ArrayObjectEx::show() 695ArrayObjectEx::getIterator() 696ArrayIteratorEx::__construct() 697ArrayIteratorEx::dump() 698array(3) { 699 ["Flags"]=> 700 int(1) 701 ["OVars"]=> 702 array(5) { 703 ["pub2"]=> 704 int(1) 705 ["pro2"]=> 706 int(2) 707 ["pri2"]=> 708 int(3) 709 ["imp2"]=> 710 int(4) 711 ["dyn2"]=> 712 int(5) 713 } 714 ["$this"]=> 715 object(ArrayIteratorEx)#%d (6) { 716 ["pub2"]=> 717 int(1) 718 ["pro2":protected]=> 719 int(2) 720 ["pri2":"ArrayIteratorEx":private]=> 721 int(3) 722 ["imp2"]=> 723 int(4) 724 ["dyn2"]=> 725 int(5) 726 ["storage":"ArrayIterator":private]=> 727 object(ArrayObjectEx)#%d (5) { 728 ["pub1"]=> 729 int(1) 730 ["pro1":protected]=> 731 int(2) 732 ["pri1":"ArrayObjectEx":private]=> 733 int(3) 734 ["imp1"]=> 735 int(4) 736 ["dyn1"]=> 737 int(5) 738 } 739 } 740} 741array(1) { 742 ["pub1"]=> 743 int(1) 744} 745array(1) { 746 ["imp1"]=> 747 int(4) 748} 749array(1) { 750 ["dyn1"]=> 751 int(5) 752} 753===FOREACH=== 754ArrayObjectEx::getIterator() 755ArrayIteratorEx::__construct() 756ArrayIteratorEx::dump() 757array(3) { 758 ["Flags"]=> 759 int(1) 760 ["OVars"]=> 761 array(5) { 762 ["pub2"]=> 763 int(1) 764 ["pro2"]=> 765 int(2) 766 ["pri2"]=> 767 int(3) 768 ["imp2"]=> 769 int(4) 770 ["dyn2"]=> 771 int(5) 772 } 773 ["$this"]=> 774 object(ArrayIteratorEx)#%d (6) { 775 ["pub2"]=> 776 int(1) 777 ["pro2":protected]=> 778 int(2) 779 ["pri2":"ArrayIteratorEx":private]=> 780 int(3) 781 ["imp2"]=> 782 int(4) 783 ["dyn2"]=> 784 int(5) 785 ["storage":"ArrayIterator":private]=> 786 object(ArrayObjectEx)#%d (5) { 787 ["pub1"]=> 788 int(1) 789 ["pro1":protected]=> 790 int(2) 791 ["pri1":"ArrayObjectEx":private]=> 792 int(3) 793 ["imp1"]=> 794 int(4) 795 ["dyn1"]=> 796 int(5) 797 } 798 } 799} 800array(1) { 801 ["pub1"]=> 802 int(1) 803} 804array(1) { 805 ["imp1"]=> 806 int(4) 807} 808array(1) { 809 ["dyn1"]=> 810 int(5) 811} 812===PROPERTY=== 813int(1) 814bool(false) 815ArrayObjectEx::setFlags(3) 816int(1) 817bool(false) 818int(1) 819bool(false) 820ArrayIteratorEx::setFlags(3) 821int(1) 822bool(true) 823===DONE=== 824