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