1--TEST--
2DOMDocument liveness caching invalidation by textContent
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7$doc = new DOMDocument;
8$doc->loadXML('<root><e id="1"/><e id="2"/><e id="3"/><e id="4"/><e id="5"/></root>');
9$root = $doc->documentElement;
10
11$i = 0;
12
13echo "-- Overwrite during iteration --\n";
14
15foreach ($doc->getElementsByTagName('e') as $node) {
16    if ($i++ == 2) {
17        $root->textContent = 'overwrite';
18    }
19    var_dump($node->tagName, $node->getAttribute('id'));
20}
21
22echo "-- Empty iteration --\n";
23foreach ($doc->getElementsByTagName('e') as $node) {
24    echo "Should not execute\n";
25}
26
27echo "-- After adding an element again --\n";
28$root->appendChild(new DOMElement('e'));
29foreach ($doc->getElementsByTagName('e') as $node) {
30    echo "Should execute once\n";
31}
32?>
33--EXPECT--
34-- Overwrite during iteration --
35string(1) "e"
36string(1) "1"
37string(1) "e"
38string(1) "2"
39string(1) "e"
40string(1) "3"
41-- Empty iteration --
42-- After adding an element again --
43Should execute once
44