xref: /PHP-5.5/ext/spl/tests/iterator_014.phpt (revision 610c7fbe)
1--TEST--
2SPL: RecursiveIteratorIterator and beginChildren/endChildren
3--FILE--
4<?php
5
6class MyRecursiveArrayIterator extends RecursiveArrayIterator
7{
8	function valid()
9	{
10		if (!parent::valid())
11		{
12			echo __METHOD__ . " = false\n";
13			return false;
14		}
15		else
16		{
17			return true;
18		}
19	}
20
21	function getChildren()
22	{
23		echo __METHOD__ . "\n";
24		return parent::getChildren();
25	}
26}
27
28class RecursiveArrayIteratorIterator extends RecursiveIteratorIterator
29{
30	function rewind()
31	{
32		echo __METHOD__ . "\n";
33		parent::rewind();
34	}
35
36	function valid()
37	{
38		echo __METHOD__ . "\n";
39		return parent::valid();
40	}
41
42	function current()
43	{
44		echo __METHOD__ . "\n";
45		return parent::current();
46	}
47
48	function key()
49	{
50		echo __METHOD__ . "\n";
51		return parent::key();
52	}
53
54	function next()
55	{
56		echo __METHOD__ . "\n";
57		parent::next();
58	}
59
60	function beginChildren()
61	{
62		echo __METHOD__ . "(".$this->getDepth().")\n";
63	}
64
65	function endChildren()
66	{
67		echo __METHOD__ . "(".$this->getDepth().")\n";
68	}
69}
70
71foreach(new RecursiveArrayIteratorIterator(new MyRecursiveArrayIterator(array("a", array("ba", array("bba", "bbb"), array(array("bcaa"))), array("ca"), "d"))) as $k=>$v)
72{
73	echo "$k=>$v\n";
74}
75?>
76===DONE===
77<?php exit(0); ?>
78--EXPECT--
79RecursiveArrayIteratorIterator::rewind
80RecursiveArrayIteratorIterator::valid
81RecursiveArrayIteratorIterator::current
82RecursiveArrayIteratorIterator::key
830=>a
84RecursiveArrayIteratorIterator::next
85MyRecursiveArrayIterator::getChildren
86RecursiveArrayIteratorIterator::beginChildren(1)
87RecursiveArrayIteratorIterator::valid
88RecursiveArrayIteratorIterator::current
89RecursiveArrayIteratorIterator::key
900=>ba
91RecursiveArrayIteratorIterator::next
92MyRecursiveArrayIterator::getChildren
93RecursiveArrayIteratorIterator::beginChildren(2)
94RecursiveArrayIteratorIterator::valid
95RecursiveArrayIteratorIterator::current
96RecursiveArrayIteratorIterator::key
970=>bba
98RecursiveArrayIteratorIterator::next
99RecursiveArrayIteratorIterator::valid
100RecursiveArrayIteratorIterator::current
101RecursiveArrayIteratorIterator::key
1021=>bbb
103RecursiveArrayIteratorIterator::next
104MyRecursiveArrayIterator::valid = false
105RecursiveArrayIteratorIterator::endChildren(2)
106MyRecursiveArrayIterator::getChildren
107RecursiveArrayIteratorIterator::beginChildren(2)
108MyRecursiveArrayIterator::getChildren
109RecursiveArrayIteratorIterator::beginChildren(3)
110RecursiveArrayIteratorIterator::valid
111RecursiveArrayIteratorIterator::current
112RecursiveArrayIteratorIterator::key
1130=>bcaa
114RecursiveArrayIteratorIterator::next
115MyRecursiveArrayIterator::valid = false
116RecursiveArrayIteratorIterator::endChildren(3)
117MyRecursiveArrayIterator::valid = false
118RecursiveArrayIteratorIterator::endChildren(2)
119MyRecursiveArrayIterator::valid = false
120RecursiveArrayIteratorIterator::endChildren(1)
121MyRecursiveArrayIterator::getChildren
122RecursiveArrayIteratorIterator::beginChildren(1)
123RecursiveArrayIteratorIterator::valid
124RecursiveArrayIteratorIterator::current
125RecursiveArrayIteratorIterator::key
1260=>ca
127RecursiveArrayIteratorIterator::next
128MyRecursiveArrayIterator::valid = false
129RecursiveArrayIteratorIterator::endChildren(1)
130RecursiveArrayIteratorIterator::valid
131RecursiveArrayIteratorIterator::current
132RecursiveArrayIteratorIterator::key
1333=>d
134RecursiveArrayIteratorIterator::next
135MyRecursiveArrayIterator::valid = false
136RecursiveArrayIteratorIterator::valid
137MyRecursiveArrayIterator::valid = false
138===DONE===
139