1--TEST-- 2Bug #79701 (getElementById does not correctly work with duplicate definitions) - set attribute in html variation 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7foreach (["xml:id", "ID"] as $name) { 8 $dom = Dom\HTMLDocument::createFromString(<<<HTML 9 <p> 10 <em id="x">1</em> 11 <strong id="y">2</strong> 12 </p> 13 HTML, LIBXML_NOERROR); 14 15 echo "\n=== Attribute name $name ===\n\n"; 16 17 $test1 = $dom->getElementById('x'); 18 $test2 = $dom->getElementById('y'); 19 20 echo "--- After resetting em's id ---\n"; 21 22 $test1->setAttribute($name, 'y'); 23 var_dump($dom->getElementById('x')?->nodeName); 24 var_dump($dom->getElementById('y')?->nodeName); 25 26 echo "--- After resetting strong's id ---\n"; 27 28 $test2->setAttribute($name, 'x'); 29 var_dump($dom->getElementById('x')?->nodeName); 30 var_dump($dom->getElementById('y')?->nodeName); 31 32 echo "--- After resetting em's id ---\n"; 33 34 $test1->setAttribute($name, 'z'); 35 var_dump($dom->getElementById('x')?->nodeName); 36 var_dump($dom->getElementById('y')?->nodeName); 37 38 echo "--- After resetting strong's id ---\n"; 39 40 $test2->setAttribute($name, 'z'); 41 var_dump($dom->getElementById('x')?->nodeName); 42 var_dump($dom->getElementById('y')?->nodeName); 43 44 echo "--- Get id z ---\n"; 45 46 var_dump($dom->getElementById('z')?->nodeName); 47} 48?> 49--EXPECT-- 50=== Attribute name xml:id === 51 52--- After resetting em's id --- 53string(2) "EM" 54string(6) "STRONG" 55--- After resetting strong's id --- 56string(2) "EM" 57string(6) "STRONG" 58--- After resetting em's id --- 59string(2) "EM" 60string(6) "STRONG" 61--- After resetting strong's id --- 62string(2) "EM" 63string(6) "STRONG" 64--- Get id z --- 65NULL 66 67=== Attribute name ID === 68 69--- After resetting em's id --- 70NULL 71string(2) "EM" 72--- After resetting strong's id --- 73string(6) "STRONG" 74string(2) "EM" 75--- After resetting em's id --- 76string(6) "STRONG" 77NULL 78--- After resetting strong's id --- 79NULL 80NULL 81--- Get id z --- 82string(2) "EM" 83