xref: /PHP-8.2/ext/simplexml/tests/033.phpt (revision 7f2f0c00)
1--TEST--
2SimpleXML: casting instances
3--EXTENSIONS--
4simplexml
5--FILE--
6<?php
7
8$xml =<<<EOF
9<people>
10test
11  <person name="Joe"/>
12  <person name="John">
13    <children>
14      <person name="Joe"/>
15    </children>
16  </person>
17  <person name="Jane"/>
18</people>
19EOF;
20
21$foo = simplexml_load_string( "<foo />" );
22$people = simplexml_load_string($xml);
23
24var_dump((bool)$foo);
25var_dump((bool)$people);
26var_dump((int)$foo);
27var_dump((int)$people);
28var_dump((double)$foo);
29var_dump((double)$people);
30var_dump((string)$foo);
31var_dump((string)$people);
32var_dump((array)$foo);
33var_dump((array)$people);
34var_dump((object)$foo);
35var_dump((object)$people);
36
37?>
38--EXPECTF--
39bool(false)
40bool(true)
41int(0)
42int(0)
43float(0)
44float(0)
45string(0) ""
46string(15) "
47test
48
49
50
51"
52array(0) {
53}
54array(1) {
55  ["person"]=>
56  array(3) {
57    [0]=>
58    object(SimpleXMLElement)#%d (1) {
59      ["@attributes"]=>
60      array(1) {
61        ["name"]=>
62        string(3) "Joe"
63      }
64    }
65    [1]=>
66    object(SimpleXMLElement)#%d (2) {
67      ["@attributes"]=>
68      array(1) {
69        ["name"]=>
70        string(4) "John"
71      }
72      ["children"]=>
73      object(SimpleXMLElement)#%d (1) {
74        ["person"]=>
75        object(SimpleXMLElement)#%d (1) {
76          ["@attributes"]=>
77          array(1) {
78            ["name"]=>
79            string(3) "Joe"
80          }
81        }
82      }
83    }
84    [2]=>
85    object(SimpleXMLElement)#%d (1) {
86      ["@attributes"]=>
87      array(1) {
88        ["name"]=>
89        string(4) "Jane"
90      }
91    }
92  }
93}
94object(SimpleXMLElement)#%d (0) {
95}
96object(SimpleXMLElement)#%d (1) {
97  ["person"]=>
98  array(3) {
99    [0]=>
100    object(SimpleXMLElement)#%d (1) {
101      ["@attributes"]=>
102      array(1) {
103        ["name"]=>
104        string(3) "Joe"
105      }
106    }
107    [1]=>
108    object(SimpleXMLElement)#%d (2) {
109      ["@attributes"]=>
110      array(1) {
111        ["name"]=>
112        string(4) "John"
113      }
114      ["children"]=>
115      object(SimpleXMLElement)#%d (1) {
116        ["person"]=>
117        object(SimpleXMLElement)#%d (1) {
118          ["@attributes"]=>
119          array(1) {
120            ["name"]=>
121            string(3) "Joe"
122          }
123        }
124      }
125    }
126    [2]=>
127    object(SimpleXMLElement)#%d (1) {
128      ["@attributes"]=>
129      array(1) {
130        ["name"]=>
131        string(4) "Jane"
132      }
133    }
134  }
135}
136