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