summaryrefslogtreecommitdiff
path: root/ext/spl/tests/iterator_055.phpt
blob: 851d6ed666a9a93db807dfe58572270763a8521d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
--TEST--
SPL: RegexIterator::SPLIT, USE_KEY
--SKIPIF--
<?php if (!extension_loaded("spl")) print "skip"; ?>
--FILE--
<?php

class MyRegexIterator extends RegexIterator
{
	function show()
	{
		foreach($this as $k => $v)
		{
			var_dump($k);
			var_dump($v);
		}
	}
}

$ar = new ArrayIterator(array('1'=>0,'1,2'=>1,'1,2,3'=>2,0=>3,'FooBar'=>4,','=>5,',,'=>6));
$it = new MyRegexIterator($ar, '/(\d),(\d)/', RegexIterator::SPLIT, RegexIterator::USE_KEY);

$it->show();

var_dump($ar);

?>
===DONE===
<?php exit(0); ?>
--EXPECTF--
string(3) "1,2"
array(2) {
  [0]=>
  string(0) ""
  [1]=>
  string(0) ""
}
string(5) "1,2,3"
array(2) {
  [0]=>
  string(0) ""
  [1]=>
  string(2) ",3"
}
object(ArrayIterator)#%d (1) {
  ["storage":"ArrayIterator":private]=>
  array(7) {
    [1]=>
    int(0)
    ["1,2"]=>
    int(1)
    ["1,2,3"]=>
    int(2)
    [0]=>
    int(3)
    ["FooBar"]=>
    int(4)
    [","]=>
    int(5)
    [",,"]=>
    int(6)
  }
}
===DONE===