arrayObject_getIteratorClass_basic1.phpt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. --TEST--
  2. SPL: ArrayObject::getIteratorClass and ArrayObject::setIteratorClass basic functionality
  3. --FILE--
  4. <?php
  5. class MyIterator extends ArrayIterator {
  6. function __construct() {
  7. $args = func_get_args();
  8. echo " In " . __METHOD__ . "(" . implode($args, ',') . ")\n";
  9. }
  10. function rewind() {
  11. $args = func_get_args();
  12. echo " In " . __METHOD__ . "(" . implode($args, ',') . ")\n";
  13. return parent::rewind();
  14. }
  15. function valid() {
  16. $args = func_get_args();
  17. echo " In " . __METHOD__ . "(" . implode($args, ',') . ")\n";
  18. return parent::valid();
  19. }
  20. function current() {
  21. $args = func_get_args();
  22. echo " In " . __METHOD__ . "(" . implode($args, ',') . ")\n";
  23. return parent::current();
  24. }
  25. function next() {
  26. $args = func_get_args();
  27. echo " In " . __METHOD__ . "(" . implode($args, ',') . ")\n";
  28. return parent::next();
  29. }
  30. function key() {
  31. $args = func_get_args();
  32. echo " In " . __METHOD__ . "(" . implode($args, ',') . ")\n";
  33. return parent::key();
  34. }
  35. }
  36. $ao = new ArrayObject(array('a'=>1,'b'=>2,'c'=>3), 0, "MyIterator");
  37. echo "--> Access using MyIterator:\n";
  38. var_dump($ao->getIteratorClass());
  39. var_dump($ao->getIterator());
  40. foreach($ao as $key=>$value) {
  41. echo " $key=>$value\n";
  42. }
  43. echo "\n\n--> Access using ArrayIterator:\n";
  44. var_dump($ao->setIteratorClass("ArrayIterator"));
  45. var_dump($ao->getIteratorClass());
  46. var_dump($ao->getIterator());
  47. foreach($ao as $key=>$value) {
  48. echo "$key=>$value\n";
  49. }
  50. ?>
  51. --EXPECTF--
  52. --> Access using MyIterator:
  53. string(10) "MyIterator"
  54. object(MyIterator)#2 (1) {
  55. ["storage":"ArrayIterator":private]=>
  56. object(ArrayObject)#1 (1) {
  57. ["storage":"ArrayObject":private]=>
  58. array(3) {
  59. ["a"]=>
  60. int(1)
  61. ["b"]=>
  62. int(2)
  63. ["c"]=>
  64. int(3)
  65. }
  66. }
  67. }
  68. In MyIterator::rewind()
  69. In MyIterator::valid()
  70. In MyIterator::current()
  71. In MyIterator::key()
  72. a=>1
  73. In MyIterator::next()
  74. In MyIterator::valid()
  75. In MyIterator::current()
  76. In MyIterator::key()
  77. b=>2
  78. In MyIterator::next()
  79. In MyIterator::valid()
  80. In MyIterator::current()
  81. In MyIterator::key()
  82. c=>3
  83. In MyIterator::next()
  84. In MyIterator::valid()
  85. --> Access using ArrayIterator:
  86. NULL
  87. string(13) "ArrayIterator"
  88. object(ArrayIterator)#3 (1) {
  89. ["storage":"ArrayIterator":private]=>
  90. object(ArrayObject)#1 (1) {
  91. ["storage":"ArrayObject":private]=>
  92. array(3) {
  93. ["a"]=>
  94. int(1)
  95. ["b"]=>
  96. int(2)
  97. ["c"]=>
  98. int(3)
  99. }
  100. }
  101. }
  102. a=>1
  103. b=>2
  104. c=>3