xref: /PHP-5.3/ext/spl/tests/iterator_042.phpt (revision 610c7fbe)
1--TEST--
2SPL: AppendIterator and its ArrayIterator
3--FILE--
4<?php
5
6function test_error_handler($errno, $msg, $filename, $linenum, $vars)
7{
8	echo "Error $msg in $filename on line $linenum\n";
9	return true;
10}
11
12set_error_handler('test_error_handler');
13
14$it = new AppendIterator;
15
16$it->append(array());
17$it->append(new ArrayIterator(array(1)));
18$it->append(new ArrayIterator(array(21, 22)));
19
20var_dump($it->getArrayIterator());
21
22$it->append(new ArrayIterator(array(31, 32, 33)));
23
24var_dump($it->getArrayIterator());
25
26$idx = 0;
27
28foreach($it as $k => $v)
29{
30	echo '===' . $idx++ . "===\n";
31	var_dump($it->getIteratorIndex());
32	var_dump($k);
33	var_dump($v);
34}
35
36?>
37===DONE===
38<?php exit(0); ?>
39--EXPECTF--
40Error Argument 1 passed to AppendIterator::append() must implement interface Iterator, array given in %siterator_042.php on line %d
41object(ArrayIterator)#%d (1) {
42  %s"storage"%s"ArrayIterator":private]=>
43  array(2) {
44    [0]=>
45    object(ArrayIterator)#%d (1) {
46      %s"storage"%s"ArrayIterator":private]=>
47      array(1) {
48        [0]=>
49        int(1)
50      }
51    }
52    [1]=>
53    object(ArrayIterator)#%d (1) {
54      %s"storage"%s"ArrayIterator":private]=>
55      array(2) {
56        [0]=>
57        int(21)
58        [1]=>
59        int(22)
60      }
61    }
62  }
63}
64object(ArrayIterator)#%d (1) {
65  %s"storage"%s"ArrayIterator":private]=>
66  array(3) {
67    [0]=>
68    object(ArrayIterator)#%d (1) {
69      %s"storage"%s"ArrayIterator":private]=>
70      array(1) {
71        [0]=>
72        int(1)
73      }
74    }
75    [1]=>
76    object(ArrayIterator)#%d (1) {
77      %s"storage"%s"ArrayIterator":private]=>
78      array(2) {
79        [0]=>
80        int(21)
81        [1]=>
82        int(22)
83      }
84    }
85    [2]=>
86    object(ArrayIterator)#5 (1) {
87      %s"storage"%s"ArrayIterator":private]=>
88      array(3) {
89        [0]=>
90        int(31)
91        [1]=>
92        int(32)
93        [2]=>
94        int(33)
95      }
96    }
97  }
98}
99===0===
100int(0)
101int(0)
102int(1)
103===1===
104int(1)
105int(0)
106int(21)
107===2===
108int(1)
109int(1)
110int(22)
111===3===
112int(2)
113int(0)
114int(31)
115===4===
116int(2)
117int(1)
118int(32)
119===5===
120int(2)
121int(2)
122int(33)
123===DONE===
124