bug45614.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --TEST--
  2. SPL: Bug#45614 (ArrayIterator can show 1st private prop of wrapped object)
  3. --FILE--
  4. <?php
  5. class C {
  6. private $priv1 = 'secret1';
  7. private $priv2 = 'secret2';
  8. public $pub1 = 'public1';
  9. public $pub2 = 'public2';
  10. public $pub3 = 'public3';
  11. public $pub4 = 'public4';
  12. }
  13. function showFirstTwoItems($it) {
  14. echo str_replace("\0", '\0', $it->key()) . " => " . $it->current() .
  15. "\n";
  16. $it->next();
  17. echo str_replace("\0", '\0', $it->key()) . " => " . $it->current() .
  18. "\n";
  19. }
  20. $ao = new ArrayObject(new C);
  21. $ai = $ao->getIterator();
  22. echo "--> Show the first two items:\n";
  23. showFirstTwoItems($ai);
  24. echo "\n--> Rewind and show the first two items:\n";
  25. $ai->rewind();
  26. showFirstTwoItems($ai);
  27. echo "\n--> Invalidate current position and show the first two items:\n";
  28. unset($ai[$ai->key()]);
  29. $ai->current();
  30. showFirstTwoItems($ai);
  31. echo "\n--> Rewind, seek and show the first two items:\n";
  32. $ai->rewind();
  33. $ai->seek(0);
  34. showFirstTwoItems($ai);
  35. ?>
  36. --EXPECT--
  37. --> Show the first two items:
  38. pub1 => public1
  39. pub2 => public2
  40. --> Rewind and show the first two items:
  41. pub1 => public1
  42. pub2 => public2
  43. --> Invalidate current position and show the first two items:
  44. pub3 => public3
  45. pub4 => public4
  46. --> Rewind, seek and show the first two items:
  47. pub1 => public1
  48. pub3 => public3