iterator_044.phpt 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. --TEST--
  2. SPL: CachingIterator and offsetGet/Exists using flag FULL_CACHE
  3. --FILE--
  4. <?php
  5. class MyFoo
  6. {
  7. function __toString()
  8. {
  9. return 'foo';
  10. }
  11. }
  12. class MyCachingIterator extends CachingIterator
  13. {
  14. function __construct(Iterator $it, $flags = 0)
  15. {
  16. parent::__construct($it, $flags);
  17. }
  18. function test($ar)
  19. {
  20. foreach($ar as $k => $v)
  21. {
  22. echo "===$k===\n";
  23. var_dump($v);
  24. var_dump($this->offsetExists($v));
  25. var_dump($this->offsetGet($v));
  26. }
  27. }
  28. }
  29. $it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4)));
  30. try
  31. {
  32. var_dump($it->offsetExists(0));
  33. }
  34. catch(Exception $e)
  35. {
  36. echo "Exception: " . $e->getMessage() . "\n";
  37. }
  38. try
  39. {
  40. var_dump($it->offsetGet(0));
  41. }
  42. catch(Exception $e)
  43. {
  44. echo "Exception: " . $e->getMessage() . "\n";
  45. }
  46. $it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4)), CachingIterator::FULL_CACHE);
  47. var_dump($it->offsetExists());
  48. var_dump($it->offsetGet());
  49. $checks = array(0, new stdClass, new MyFoo, NULL, 2, 'foo', 3);
  50. $it->test($checks);
  51. echo "===FILL===\n";
  52. foreach($it as $v); // read all into cache
  53. $it->test($checks);
  54. ?>
  55. ===DONE===
  56. <?php exit(0); ?>
  57. --EXPECTF--
  58. Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct)
  59. Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct)
  60. Warning: CachingIterator::offsetExists() expects exactly 1 parameter, 0 given in %siterator_044.php on line %d
  61. NULL
  62. Warning: CachingIterator::offsetGet() expects exactly 1 parameter, 0 given in %siterator_044.php on line %d
  63. NULL
  64. ===0===
  65. int(0)
  66. bool(false)
  67. Notice: Undefined index: 0 in %siterator_044.php on line %d
  68. NULL
  69. ===1===
  70. object(stdClass)#%d (0) {
  71. }
  72. Warning: CachingIterator::offsetExists() expects parameter 1 to be string, object given in %siterator_044.php on line %d
  73. NULL
  74. Warning: CachingIterator::offsetGet() expects parameter 1 to be string, object given in %siterator_044.php on line %d
  75. NULL
  76. ===2===
  77. object(MyFoo)#%d (0) {
  78. }
  79. bool(false)
  80. Notice: Undefined index: foo in %siterator_044.php on line %d
  81. NULL
  82. ===3===
  83. NULL
  84. bool(false)
  85. Notice: Undefined index: in %siterator_044.php on line %d
  86. NULL
  87. ===4===
  88. int(2)
  89. bool(false)
  90. Notice: Undefined index: 2 in %siterator_044.php on line %d
  91. NULL
  92. ===5===
  93. string(3) "foo"
  94. bool(false)
  95. Notice: Undefined index: foo in %siterator_044.php on line %d
  96. NULL
  97. ===6===
  98. int(3)
  99. bool(false)
  100. Notice: Undefined index: 3 in %siterator_044.php on line %d
  101. NULL
  102. ===FILL===
  103. ===0===
  104. int(0)
  105. bool(true)
  106. int(0)
  107. ===1===
  108. object(stdClass)#1 (0) {
  109. }
  110. Warning: CachingIterator::offsetExists() expects parameter 1 to be string, object given in %siterator_044.php on line %d
  111. NULL
  112. Warning: CachingIterator::offsetGet() expects parameter 1 to be string, object given in %siterator_044.php on line %d
  113. NULL
  114. ===2===
  115. object(MyFoo)#2 (0) {
  116. }
  117. bool(true)
  118. int(1)
  119. ===3===
  120. NULL
  121. bool(false)
  122. Notice: Undefined index: in %siterator_044.php on line %d
  123. NULL
  124. ===4===
  125. int(2)
  126. bool(true)
  127. int(4)
  128. ===5===
  129. string(3) "foo"
  130. bool(true)
  131. int(1)
  132. ===6===
  133. int(3)
  134. bool(false)
  135. Notice: Undefined index: 3 in %siterator_044.php on line %d
  136. NULL
  137. ===DONE===