File: Element_setAttributeNode_adoption.phpt

package info (click to toggle)
php8.4 8.4.11-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 208,108 kB
  • sloc: ansic: 1,060,628; php: 35,345; sh: 11,866; cpp: 7,201; pascal: 4,913; javascript: 3,091; asm: 2,810; yacc: 2,411; makefile: 689; xml: 446; python: 301; awk: 148
file content (55 lines) | stat: -rw-r--r-- 1,388 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
--TEST--
Dom\Element::setAttributeNode(NS) adopting from another document
--EXTENSIONS--
dom
--FILE--
<?php

$dom1 = Dom\HTMLDocument::createEmpty();
$container = $dom1->appendChild($dom1->createElement("container"));

echo "--- Without namespace ---\n";

$dom2 = Dom\HTMLDocument::createEmpty();
$attr = $dom2->createAttribute("my-attribute");
$attr->value = "1";

$container->setAttributeNode($attr);
var_dump($attr->ownerDocument === $dom1);

// Should not cause problems
unset($dom2);
unset($attr);

echo "--- With namespace ---\n";

$dom2 = Dom\HTMLDocument::createEmpty();
$attr2 = $dom2->createAttributeNS("urn:a", "a:my-attribute");
$attr2->value = "2";
$dom1->documentElement->setAttributeNode($attr2);

$dom2 = Dom\HTMLDocument::createEmpty();
$attr3 = $dom2->createAttributeNS("urn:b", "a:my-attribute");
$attr3->value = "3";
$dom1->documentElement->setAttributeNode($attr3);

var_dump($attr2->prefix, $attr2->namespaceURI, $attr2->localName);
var_dump($attr3->prefix, $attr3->namespaceURI, $attr3->localName);

echo "--- Resulting document ---\n";

echo $dom1->saveHtml(), "\n";

?>
--EXPECT--
--- Without namespace ---
bool(true)
--- With namespace ---
string(1) "a"
string(5) "urn:a"
string(12) "my-attribute"
string(1) "a"
string(5) "urn:b"
string(12) "my-attribute"
--- Resulting document ---
<container my-attribute="1" a:my-attribute="2" a:my-attribute="3"></container>