iterator_044.phpt 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. try {
  25. var_dump($this->offsetExists($v));
  26. } catch (TypeError $e) {
  27. echo $e->getMessage(), "\n";
  28. }
  29. try {
  30. var_dump($this->offsetGet($v));
  31. } catch (TypeError $e) {
  32. echo $e->getMessage(), "\n";
  33. }
  34. }
  35. }
  36. }
  37. $it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4)));
  38. try
  39. {
  40. var_dump($it->offsetExists(0));
  41. }
  42. catch(Exception $e)
  43. {
  44. echo "Exception: " . $e->getMessage() . "\n";
  45. }
  46. try
  47. {
  48. var_dump($it->offsetGet(0));
  49. }
  50. catch(Exception $e)
  51. {
  52. echo "Exception: " . $e->getMessage() . "\n";
  53. }
  54. $it = new MyCachingIterator(new ArrayIterator(array(0, 'foo'=>1, 2, 'bar'=>3, 4)), CachingIterator::FULL_CACHE);
  55. $checks = array(0, new stdClass, new MyFoo, NULL, 2, 'foo', 3);
  56. $it->test($checks);
  57. echo "===FILL===\n";
  58. foreach($it as $v); // read all into cache
  59. $it->test($checks);
  60. ?>
  61. --EXPECTF--
  62. Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct)
  63. Exception: MyCachingIterator does not use a full cache (see CachingIterator::__construct)
  64. ===0===
  65. int(0)
  66. bool(false)
  67. Warning: Undefined array key "0" in %s on line %d
  68. NULL
  69. ===1===
  70. object(stdClass)#%d (0) {
  71. }
  72. CachingIterator::offsetExists(): Argument #1 ($key) must be of type string, stdClass given
  73. CachingIterator::offsetGet(): Argument #1 ($key) must be of type string, stdClass given
  74. ===2===
  75. object(MyFoo)#%d (0) {
  76. }
  77. bool(false)
  78. Warning: Undefined array key "foo" in %s on line %d
  79. NULL
  80. ===3===
  81. NULL
  82. Deprecated: CachingIterator::offsetExists(): Passing null to parameter #1 ($key) of type string is deprecated in %s on line %d
  83. bool(false)
  84. Deprecated: CachingIterator::offsetGet(): Passing null to parameter #1 ($key) of type string is deprecated in %s on line %d
  85. Warning: Undefined array key "" in %s on line %d
  86. NULL
  87. ===4===
  88. int(2)
  89. bool(false)
  90. Warning: Undefined array key "2" in %s on line %d
  91. NULL
  92. ===5===
  93. string(3) "foo"
  94. bool(false)
  95. Warning: Undefined array key "foo" in %s on line %d
  96. NULL
  97. ===6===
  98. int(3)
  99. bool(false)
  100. Warning: Undefined array key "3" in %s 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. CachingIterator::offsetExists(): Argument #1 ($key) must be of type string, stdClass given
  111. CachingIterator::offsetGet(): Argument #1 ($key) must be of type string, stdClass given
  112. ===2===
  113. object(MyFoo)#2 (0) {
  114. }
  115. bool(true)
  116. int(1)
  117. ===3===
  118. NULL
  119. Deprecated: CachingIterator::offsetExists(): Passing null to parameter #1 ($key) of type string is deprecated in %s on line %d
  120. bool(false)
  121. Deprecated: CachingIterator::offsetGet(): Passing null to parameter #1 ($key) of type string is deprecated in %s on line %d
  122. Warning: Undefined array key "" in %s 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. Warning: Undefined array key "3" in %s on line %d
  136. NULL