iterator_053.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. --TEST--
  2. SPL: RegexIterator::ALL_MATCHES
  3. --FILE--
  4. <?php
  5. class MyRegexIterator extends RegexIterator
  6. {
  7. public $uk, $re;
  8. function __construct($it, $re, $mode, $flags = 0)
  9. {
  10. $this->uk = $flags & self::USE_KEY;
  11. $this->re = $re;
  12. parent::__construct($it, $re, $mode, $flags);
  13. }
  14. function show()
  15. {
  16. foreach($this as $k => $v)
  17. {
  18. var_dump($k);
  19. var_dump($v);
  20. }
  21. }
  22. function accept(): bool
  23. {
  24. @preg_match_all($this->re, (string)($this->uk ? $this->key() : $this->current()), $sub);
  25. $ret = parent::accept();
  26. var_dump($sub == $this->current());
  27. return $ret;
  28. }
  29. }
  30. $ar = new ArrayIterator(array('1','1,2','1,2,3','',NULL,array(),'FooBar',',',',,'));
  31. $it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::ALL_MATCHES, RegexIterator::USE_KEY);
  32. $it->show();
  33. $it = new MyRegexIterator($ar, '/(\d)/', RegexIterator::ALL_MATCHES, RegexIterator::USE_KEY);
  34. $it->show();
  35. var_dump($ar);
  36. ?>
  37. --EXPECTF--
  38. bool(true)
  39. bool(true)
  40. bool(true)
  41. bool(true)
  42. bool(true)
  43. bool(true)
  44. bool(true)
  45. bool(true)
  46. bool(true)
  47. bool(true)
  48. int(0)
  49. array(2) {
  50. [0]=>
  51. array(1) {
  52. [0]=>
  53. string(1) "0"
  54. }
  55. [1]=>
  56. array(1) {
  57. [0]=>
  58. string(1) "0"
  59. }
  60. }
  61. bool(true)
  62. int(1)
  63. array(2) {
  64. [0]=>
  65. array(1) {
  66. [0]=>
  67. string(1) "1"
  68. }
  69. [1]=>
  70. array(1) {
  71. [0]=>
  72. string(1) "1"
  73. }
  74. }
  75. bool(true)
  76. int(2)
  77. array(2) {
  78. [0]=>
  79. array(1) {
  80. [0]=>
  81. string(1) "2"
  82. }
  83. [1]=>
  84. array(1) {
  85. [0]=>
  86. string(1) "2"
  87. }
  88. }
  89. bool(true)
  90. int(3)
  91. array(2) {
  92. [0]=>
  93. array(1) {
  94. [0]=>
  95. string(1) "3"
  96. }
  97. [1]=>
  98. array(1) {
  99. [0]=>
  100. string(1) "3"
  101. }
  102. }
  103. bool(true)
  104. int(4)
  105. array(2) {
  106. [0]=>
  107. array(1) {
  108. [0]=>
  109. string(1) "4"
  110. }
  111. [1]=>
  112. array(1) {
  113. [0]=>
  114. string(1) "4"
  115. }
  116. }
  117. bool(true)
  118. int(5)
  119. array(2) {
  120. [0]=>
  121. array(1) {
  122. [0]=>
  123. string(1) "5"
  124. }
  125. [1]=>
  126. array(1) {
  127. [0]=>
  128. string(1) "5"
  129. }
  130. }
  131. bool(true)
  132. int(6)
  133. array(2) {
  134. [0]=>
  135. array(1) {
  136. [0]=>
  137. string(1) "6"
  138. }
  139. [1]=>
  140. array(1) {
  141. [0]=>
  142. string(1) "6"
  143. }
  144. }
  145. bool(true)
  146. int(7)
  147. array(2) {
  148. [0]=>
  149. array(1) {
  150. [0]=>
  151. string(1) "7"
  152. }
  153. [1]=>
  154. array(1) {
  155. [0]=>
  156. string(1) "7"
  157. }
  158. }
  159. bool(true)
  160. int(8)
  161. array(2) {
  162. [0]=>
  163. array(1) {
  164. [0]=>
  165. string(1) "8"
  166. }
  167. [1]=>
  168. array(1) {
  169. [0]=>
  170. string(1) "8"
  171. }
  172. }
  173. object(ArrayIterator)#%d (1) {
  174. ["storage":"ArrayIterator":private]=>
  175. array(9) {
  176. [0]=>
  177. %s(1) "1"
  178. [1]=>
  179. %s(3) "1,2"
  180. [2]=>
  181. %s(5) "1,2,3"
  182. [3]=>
  183. %s(0) ""
  184. [4]=>
  185. NULL
  186. [5]=>
  187. array(0) {
  188. }
  189. [6]=>
  190. %s(6) "FooBar"
  191. [7]=>
  192. %s(1) ","
  193. [8]=>
  194. %s(2) ",,"
  195. }
  196. }