xref: /PHP-8.3/ext/simplexml/tests/002.phpt (revision 7f2f0c00)
1--TEST--
2SimpleXML: clone
3--EXTENSIONS--
4simplexml
5--FILE--
6<?php
7
8$xml =<<<EOF
9<?xml version='1.0'?>
10<!DOCTYPE sxe SYSTEM "notfound.dtd">
11<sxe id="elem1">
12 <elem1 attr1='first'>
13  <!-- comment -->
14  <elem2>
15   <elem3>
16    <elem4>
17     <?test processing instruction ?>
18    </elem4>
19   </elem3>
20  </elem2>
21 </elem1>
22</sxe>
23EOF;
24
25$sxe = simplexml_load_string($xml);
26
27$copy = clone $sxe;
28
29var_dump($copy);
30
31?>
32--EXPECTF--
33object(SimpleXMLElement)#%d (2) {
34  ["@attributes"]=>
35  array(1) {
36    ["id"]=>
37    string(5) "elem1"
38  }
39  ["elem1"]=>
40  object(SimpleXMLElement)#%d (3) {
41    ["@attributes"]=>
42    array(1) {
43      ["attr1"]=>
44      string(5) "first"
45    }
46    ["comment"]=>
47    object(SimpleXMLElement)#%d (0) {
48    }
49    ["elem2"]=>
50    object(SimpleXMLElement)#%d (1) {
51      ["elem3"]=>
52      object(SimpleXMLElement)#%d (1) {
53        ["elem4"]=>
54        object(SimpleXMLElement)#%d (1) {
55          ["test"]=>
56          object(SimpleXMLElement)#%d (0) {
57          }
58        }
59      }
60    }
61  }
62}
63