1--TEST--
2yield from on multiple trees needing merge, with intermediary nodes having only one child
3--FILE--
4<?php
5
6function from($levels) {
7    foreach (range(0, 2 << $levels) as $v) {
8        yield $v;
9    }
10}
11
12function gen($gen, $level) {
13    yield from (function() use ($gen) { yield from $gen; })();
14}
15
16foreach (range(0, 6) as $levels) {
17    print "$levels level".($levels == 1 ? "" : "s")."\n\n";
18
19    $all = array();
20    $all[] = $gens[0][0] = from($levels);
21
22    for ($level = 1; $level < $levels; $level++) {
23        for ($i = 0; $i < (1 << $level); $i++) {
24            $all[] = $gens[$level][$i] = gen($gens[$level-1][$i >> 1], $level);
25        }
26    }
27
28    while (1) {
29        foreach ($all as $gen) {
30            var_dump($gen->current());
31            $gen->next();
32            if (!$gen->valid()) {
33                break 2;
34            }
35        }
36    }
37
38    print "\n\n";
39}
40?>
41--EXPECT--
420 levels
43
44int(0)
45int(1)
46int(2)
47
48
491 level
50
51int(0)
52int(1)
53int(2)
54int(3)
55int(4)
56
57
582 levels
59
60int(0)
61int(1)
62int(2)
63int(3)
64int(4)
65int(5)
66int(6)
67int(7)
68int(8)
69
70
713 levels
72
73int(0)
74int(1)
75int(2)
76int(3)
77int(4)
78int(5)
79int(6)
80int(7)
81int(8)
82int(9)
83int(10)
84int(11)
85int(12)
86int(13)
87int(14)
88int(15)
89int(16)
90
91
924 levels
93
94int(0)
95int(1)
96int(2)
97int(3)
98int(4)
99int(5)
100int(6)
101int(7)
102int(8)
103int(9)
104int(10)
105int(11)
106int(12)
107int(13)
108int(14)
109int(15)
110int(16)
111int(17)
112int(18)
113int(19)
114int(20)
115int(21)
116int(22)
117int(23)
118int(24)
119int(25)
120int(26)
121int(27)
122int(28)
123int(29)
124int(30)
125int(31)
126int(32)
127
128
1295 levels
130
131int(0)
132int(1)
133int(2)
134int(3)
135int(4)
136int(5)
137int(6)
138int(7)
139int(8)
140int(9)
141int(10)
142int(11)
143int(12)
144int(13)
145int(14)
146int(15)
147int(16)
148int(17)
149int(18)
150int(19)
151int(20)
152int(21)
153int(22)
154int(23)
155int(24)
156int(25)
157int(26)
158int(27)
159int(28)
160int(29)
161int(30)
162int(31)
163int(32)
164int(33)
165int(34)
166int(35)
167int(36)
168int(37)
169int(38)
170int(39)
171int(40)
172int(41)
173int(42)
174int(43)
175int(44)
176int(45)
177int(46)
178int(47)
179int(48)
180int(49)
181int(50)
182int(51)
183int(52)
184int(53)
185int(54)
186int(55)
187int(56)
188int(57)
189int(58)
190int(59)
191int(60)
192int(61)
193int(62)
194int(63)
195int(64)
196
197
1986 levels
199
200int(0)
201int(1)
202int(2)
203int(3)
204int(4)
205int(5)
206int(6)
207int(7)
208int(8)
209int(9)
210int(10)
211int(11)
212int(12)
213int(13)
214int(14)
215int(15)
216int(16)
217int(17)
218int(18)
219int(19)
220int(20)
221int(21)
222int(22)
223int(23)
224int(24)
225int(25)
226int(26)
227int(27)
228int(28)
229int(29)
230int(30)
231int(31)
232int(32)
233int(33)
234int(34)
235int(35)
236int(36)
237int(37)
238int(38)
239int(39)
240int(40)
241int(41)
242int(42)
243int(43)
244int(44)
245int(45)
246int(46)
247int(47)
248int(48)
249int(49)
250int(50)
251int(51)
252int(52)
253int(53)
254int(54)
255int(55)
256int(56)
257int(57)
258int(58)
259int(59)
260int(60)
261int(61)
262int(62)
263int(63)
264int(64)
265int(65)
266int(66)
267int(67)
268int(68)
269int(69)
270int(70)
271int(71)
272int(72)
273int(73)
274int(74)
275int(75)
276int(76)
277int(77)
278int(78)
279int(79)
280int(80)
281int(81)
282int(82)
283int(83)
284int(84)
285int(85)
286int(86)
287int(87)
288int(88)
289int(89)
290int(90)
291int(91)
292int(92)
293int(93)
294int(94)
295int(95)
296int(96)
297int(97)
298int(98)
299int(99)
300int(100)
301int(101)
302int(102)
303int(103)
304int(104)
305int(105)
306int(106)
307int(107)
308int(108)
309int(109)
310int(110)
311int(111)
312int(112)
313int(113)
314int(114)
315int(115)
316int(116)
317int(117)
318int(118)
319int(119)
320int(120)
321int(121)
322int(122)
323int(123)
324int(124)
325int(125)
326int(126)
327int(127)
328int(128)
329