array_007.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. --TEST--
  2. SPL: ArrayObject/Iterator from IteratorAggregate
  3. --FILE--
  4. <?php
  5. // This test also needs to exclude the protected and private variables
  6. // since they cannot be accessed from the external object which iterates
  7. // them.
  8. class test implements IteratorAggregate
  9. {
  10. public $pub = "public";
  11. protected $pro = "protected";
  12. private $pri = "private";
  13. function __construct()
  14. {
  15. $this->imp = "implicit";
  16. }
  17. function getIterator(): Traversable
  18. {
  19. $it = new ArrayObject($this);
  20. return $it->getIterator();
  21. }
  22. };
  23. $test = new test;
  24. $test->dyn = "dynamic";
  25. print_r($test);
  26. print_r($test->getIterator());
  27. foreach($test as $key => $val)
  28. {
  29. echo "$key => $val\n";
  30. }
  31. ?>
  32. --EXPECT--
  33. test Object
  34. (
  35. [pub] => public
  36. [pro:protected] => protected
  37. [pri:test:private] => private
  38. [imp] => implicit
  39. [dyn] => dynamic
  40. )
  41. ArrayIterator Object
  42. (
  43. [storage:ArrayIterator:private] => ArrayObject Object
  44. (
  45. [storage:ArrayObject:private] => test Object
  46. (
  47. [pub] => public
  48. [pro:protected] => protected
  49. [pri:test:private] => private
  50. [imp] => implicit
  51. [dyn] => dynamic
  52. )
  53. )
  54. )
  55. pub => public
  56. imp => implicit
  57. dyn => dynamic