--TEST-- DOMDocument node list item cache invalidation --EXTENSIONS-- dom --FILE-- loadHTML('

hello

world

'); $elements = $doc->getElementsByTagName('p'); $elements->item(0); // Activate item cache $doc->loadHTML('

A

B

C

'); var_dump($elements); var_dump($elements->item(0)->textContent); // First lookup var_dump($elements->item(2)->textContent); // Uses cache var_dump($elements->item(1)->textContent); // Does not use cache echo "-- Remove cached item test --\n"; $doc = new DOMDocument(); $doc->loadHTML('

hello

world

!

'); $elements = $doc->getElementsByTagName('p'); $item = $elements->item(0); // Activate item cache var_dump($item->textContent); $item->remove(); // Now element 0 means "world", and 1 means "!" unset($item); $item = $elements->item(1); var_dump($item->textContent); echo "-- Removal of cached item in loop test --\n"; $doc = new DOMDocument; $doc->loadXML( '' ); $root = $doc->documentElement; $i = 0; $elements = $root->getElementsByTagName('e'); for ($i = 0; $i < 11; $i++) { $node = $elements->item($i); print $node->getAttribute('i') . ' '; if ($i++ % 2 == 0) $root->removeChild( $node ); } print "\n"; ?> --EXPECTF-- -- Switch document test -- object(DOMNodeList)#2 (1) { ["length"]=> int(3) } string(1) "A" string(1) "C" string(1) "B" -- Remove cached item test -- string(5) "hello" string(1) "!" -- Removal of cached item in loop test -- 1 4 7 10 13 Fatal error: Uncaught Error: Call to a member function getAttribute() on null in %s:%d Stack trace: #0 {main} thrown in %s on line %d