1--TEST--
2DOMDocument::getElementsByTagName() is live
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7$doc = new DOMDocument;
8$doc->loadXML( '<root><e i="1"/><e i="2"/><e i="3"/><e i="4"/><e i="5"/><e i="6"/><e i="7"/><e i="8"/><e i="9"/><e i="10"/><e i="11"/><e i="12"/><e i="13"/><e i="14"/><e i="15"/></root>' );
9$root = $doc->documentElement;
10
11$i = 0;
12
13/* Note that the list is live. The explanation for the output is as follows:
14   Before the loop we have the following (writing only the attributes):
15   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16
17   Now the loop starts, the current element is marked with a V. $i == 0:
18   V
19   1  2  3  4  5  6  7  8  9  10  11  12  13  14  15
20   1 gets printed. $i == 0, which is even, so 1 gets removed, which results in:
21   V
22   2  3  4  5  6  7  8  9  10  11  12  13  14  15
23   Note that everything shifted to the left.
24   Because the list is live, the current element pointer still refers to the first index, which now corresponds to element with attribute 2.
25   Now the foreach body ends, which means we go to the next element, which is now 3 instead of 2.
26      V
27   2  3  4  5  6  7  8  9  10  11  12  13  14  15
28   3 gets printed. $i == 1, which is odd, so nothing happens and we move on to the next element:
29         V
30   2  3  4  5  6  7  8  9  10  11  12  13  14  15
31   4 gets printed. $i == 2, which is even, so 4 gets removed, which results in:
32         V
33   2  3  5  6  7  8  9  10  11  12  13  14  15
34   Note again everything shifted to the left.
35   Now the foreach body ends, which means we go to the next element, which is now 6 instead of 5.
36            V
37   2  3  5  6  7  8  9  10  11  12  13  14  15
38   6 gets printed, etc... */
39foreach ($doc->getElementsByTagName('e') as $node) {
40	print $node->getAttribute('i') . ' ';
41	if ($i++ % 2 == 0)
42		$root->removeChild($node);
43}
44print "\n";
45?>
46--EXPECT--
471 3 4 6 7 9 10 12 13 15
48