1--TEST-- 2Test: setAttributeNode() 3--EXTENSIONS-- 4dom 5--FILE-- 6<?php 7 8$xml = <<<HERE 9<?xml version="1.0" ?> 10<root a="b" /> 11HERE; 12 13$xml2 = <<<HERE 14<?xml version="1.0" ?> 15<doc2 /> 16HERE; 17 18$dom = new DOMDocument(); 19$dom->loadXML($xml); 20$root = $dom->documentElement; 21$attr = $root->getAttributeNode('a'); 22 23$dom2 = new DOMDocument(); 24$dom2->loadXML($xml2); 25$root2 = $dom2->documentElement; 26try { 27 $root2->setAttributeNode($attr); 28} catch (domexception $e) { 29ob_start(); 30 var_dump($e); 31 $contents = ob_get_contents(); 32 ob_end_clean(); 33 echo preg_replace('/object\(DOMAttr\).+\{.*?\}/s', 'DOMAttr', $contents); 34} 35 36?> 37--EXPECTF-- 38object(DOMException)#%d (7) { 39 ["message":protected]=> 40 string(20) "Wrong Document Error" 41 ["string":"Exception":private]=> 42 string(0) "" 43 ["code"]=> 44 int(4) 45 ["file":protected]=> 46 string(%d) "%sdom_set_attr_node.php" 47 ["line":protected]=> 48 int(%d) 49 ["trace":"Exception":private]=> 50 array(1) { 51 [0]=> 52 array(6) { 53 ["file"]=> 54 string(%d) "%sdom_set_attr_node.php" 55 ["line"]=> 56 int(%d) 57 ["function"]=> 58 string(16) "setAttributeNode" 59 ["class"]=> 60 string(10) "DOMElement" 61 ["type"]=> 62 string(2) "->" 63 ["args"]=> 64 array(1) { 65 [0]=> 66 DOMAttr 67 } 68 } 69 } 70 ["previous":"Exception":private]=> 71 NULL 72} 73