xref: /PHP-8.3/ext/dom/tests/clone_nodes.phpt (revision d04f48b6)
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 (10) {
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  ["isConnected"]=>
61  bool(true)
62  ["ownerDocument"]=>
63  string(22) "(object value omitted)"
64  ["parentNode"]=>
65  string(22) "(object value omitted)"
66  ["parentElement"]=>
67  string(22) "(object value omitted)"
68}
69string(19) "http://php.net/test"
70string(3) "foo"
71string(19) "http://php.net/test"
72string(3) "foo"
73-- Clone DOMNode --
74string(3) "bar"
75string(3) "bar"
76NULL
77