xref: /PHP-8.2/ext/dom/tests/clone_nodes.phpt (revision 10d94aca)
1--TEST--
2Clone nodes
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8echo "-- Clone DOMNameSpaceNode --\n";
9
10$doc = new DOMDocument;
11$doc->loadXML('<foo xmlns="http://php.net/test" xmlns:foo="urn:foo" />');
12
13$attr = $doc->documentElement->getAttributeNode('xmlns');
14var_dump($attr);
15
16$attrClone = clone $attr;
17var_dump($attrClone->nodeValue);
18var_dump($attrClone->parentNode->nodeName);
19
20unset($doc);
21unset($attr);
22
23var_dump($attrClone->nodeValue);
24var_dump($attrClone->parentNode->nodeName);
25
26echo "-- Clone DOMNode --\n";
27
28$doc = new DOMDocument;
29$doc->loadXML('<foo><bar/></foo>');
30
31$bar = $doc->documentElement->firstChild;
32$barClone = clone $bar;
33$bar->remove();
34unset($bar);
35
36var_dump($barClone->nodeName);
37
38$doc->firstElementChild->remove();
39unset($doc);
40
41var_dump($barClone->nodeName);
42var_dump($barClone->parentNode);
43
44?>
45--EXPECT--
46-- Clone DOMNameSpaceNode --
47object(DOMNameSpaceNode)#3 (8) {
48  ["nodeName"]=>
49  string(5) "xmlns"
50  ["nodeValue"]=>
51  string(19) "http://php.net/test"
52  ["nodeType"]=>
53  int(18)
54  ["prefix"]=>
55  string(0) ""
56  ["localName"]=>
57  string(5) "xmlns"
58  ["namespaceURI"]=>
59  string(19) "http://php.net/test"
60  ["ownerDocument"]=>
61  string(22) "(object value omitted)"
62  ["parentNode"]=>
63  string(22) "(object value omitted)"
64}
65string(19) "http://php.net/test"
66string(3) "foo"
67string(19) "http://php.net/test"
68string(3) "foo"
69-- Clone DOMNode --
70string(3) "bar"
71string(3) "bar"
72NULL
73