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