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(false) 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(false) 128bool(true) 129int(6) 130array(2) { 131 [0]=> 132 array(1) { 133 [0]=> 134 string(1) "6" 135 } 136 [1]=> 137 array(1) { 138 [0]=> 139 string(1) "6" 140 } 141} 142bool(true) 143int(7) 144array(2) { 145 [0]=> 146 array(1) { 147 [0]=> 148 string(1) "7" 149 } 150 [1]=> 151 array(1) { 152 [0]=> 153 string(1) "7" 154 } 155} 156bool(true) 157int(8) 158array(2) { 159 [0]=> 160 array(1) { 161 [0]=> 162 string(1) "8" 163 } 164 [1]=> 165 array(1) { 166 [0]=> 167 string(1) "8" 168 } 169} 170object(ArrayIterator)#%d (1) { 171 ["storage":"ArrayIterator":private]=> 172 array(9) { 173 [0]=> 174 %s(1) "1" 175 [1]=> 176 %s(3) "1,2" 177 [2]=> 178 %s(5) "1,2,3" 179 [3]=> 180 %s(0) "" 181 [4]=> 182 NULL 183 [5]=> 184 array(0) { 185 } 186 [6]=> 187 %s(6) "FooBar" 188 [7]=> 189 %s(1) "," 190 [8]=> 191 %s(2) ",," 192 } 193} 194===DONE=== 195