xref: /php-src/ext/simplexml/tests/000.phpt (revision 7f2f0c00)
1--TEST--
2SimpleXML: var_dump()
3--EXTENSIONS--
4simplexml
5--FILE--
6<?php
7
8$sxe = simplexml_load_file(__DIR__.'/000.xml');
9
10function test($what)
11{
12    global $sxe;
13    echo "===$what\n";
14    eval("var_dump(isset(\$$what));");
15    eval("var_dump((bool)\$$what);");
16    eval("if (isset(\$$what)) var_dump(count(\$$what));");
17    eval("var_dump(\$$what);");
18}
19
20test('sxe');
21test('sxe->elem1');
22test('sxe->elem1[0]');
23test('sxe->elem1[0]->elem2');
24test('sxe->elem1[0]->elem2->bla');
25test('sxe->elem1[0]["attr1"]');
26test('sxe->elem1[0]->attr1');
27test('sxe->elem1[1]');
28test('sxe->elem1[2]');
29test('sxe->elem11');
30test('sxe->elem11->elem111');
31test('sxe->elem11->elem111->elem1111');
32test('sxe->elem22');
33test('sxe->elem22->elem222');
34test('sxe->elem22->attr22');
35test('sxe->elem22["attr22"]');
36
37?>
38--EXPECTF--
39===sxe
40bool(true)
41bool(true)
42int(3)
43object(SimpleXMLElement)#%d (3) {
44  ["@attributes"]=>
45  array(1) {
46    ["id"]=>
47    string(3) "123"
48  }
49  ["elem1"]=>
50  array(2) {
51    [0]=>
52    string(36) "There is some text.Here is some more"
53    [1]=>
54    object(SimpleXMLElement)#%d (1) {
55      ["@attributes"]=>
56      array(2) {
57        ["attr1"]=>
58        string(2) "11"
59        ["attr2"]=>
60        string(2) "12"
61      }
62    }
63  }
64  ["elem11"]=>
65  object(SimpleXMLElement)#%d (1) {
66    ["elem111"]=>
67    object(SimpleXMLElement)#%d (1) {
68      ["elem1111"]=>
69      object(SimpleXMLElement)#%d (0) {
70      }
71    }
72  }
73}
74===sxe->elem1
75bool(true)
76bool(true)
77int(2)
78object(SimpleXMLElement)#%d (3) {
79  ["@attributes"]=>
80  array(2) {
81    ["attr1"]=>
82    string(5) "first"
83    ["attr2"]=>
84    string(6) "second"
85  }
86  ["comment"]=>
87  object(SimpleXMLElement)#%d (0) {
88  }
89  ["elem2"]=>
90  object(SimpleXMLElement)#%d (2) {
91    ["@attributes"]=>
92    array(2) {
93      ["att25"]=>
94      string(2) "25"
95      ["att42"]=>
96      string(2) "42"
97    }
98    ["elem3"]=>
99    object(SimpleXMLElement)#%d (1) {
100      ["elem4"]=>
101      object(SimpleXMLElement)#%d (1) {
102        ["test"]=>
103        object(SimpleXMLElement)#%d (0) {
104        }
105      }
106    }
107  }
108}
109===sxe->elem1[0]
110bool(true)
111bool(true)
112int(1)
113object(SimpleXMLElement)#%d (3) {
114  ["@attributes"]=>
115  array(2) {
116    ["attr1"]=>
117    string(5) "first"
118    ["attr2"]=>
119    string(6) "second"
120  }
121  ["comment"]=>
122  object(SimpleXMLElement)#%d (0) {
123  }
124  ["elem2"]=>
125  object(SimpleXMLElement)#%d (2) {
126    ["@attributes"]=>
127    array(2) {
128      ["att25"]=>
129      string(2) "25"
130      ["att42"]=>
131      string(2) "42"
132    }
133    ["elem3"]=>
134    object(SimpleXMLElement)#%d (1) {
135      ["elem4"]=>
136      object(SimpleXMLElement)#%d (1) {
137        ["test"]=>
138        object(SimpleXMLElement)#%d (0) {
139        }
140      }
141    }
142  }
143}
144===sxe->elem1[0]->elem2
145bool(true)
146bool(true)
147int(1)
148object(SimpleXMLElement)#%d (2) {
149  ["@attributes"]=>
150  array(2) {
151    ["att25"]=>
152    string(2) "25"
153    ["att42"]=>
154    string(2) "42"
155  }
156  ["elem3"]=>
157  object(SimpleXMLElement)#%d (1) {
158    ["elem4"]=>
159    object(SimpleXMLElement)#%d (1) {
160      ["test"]=>
161      object(SimpleXMLElement)#%d (0) {
162      }
163    }
164  }
165}
166===sxe->elem1[0]->elem2->bla
167bool(false)
168bool(false)
169object(SimpleXMLElement)#%d (0) {
170}
171===sxe->elem1[0]["attr1"]
172bool(true)
173bool(true)
174int(0)
175object(SimpleXMLElement)#%d (1) {
176  [0]=>
177  string(5) "first"
178}
179===sxe->elem1[0]->attr1
180bool(false)
181bool(false)
182object(SimpleXMLElement)#%d (0) {
183}
184===sxe->elem1[1]
185bool(true)
186bool(true)
187int(0)
188object(SimpleXMLElement)#%d (1) {
189  ["@attributes"]=>
190  array(2) {
191    ["attr1"]=>
192    string(2) "11"
193    ["attr2"]=>
194    string(2) "12"
195  }
196}
197===sxe->elem1[2]
198bool(false)
199bool(false)
200NULL
201===sxe->elem11
202bool(true)
203bool(true)
204int(1)
205object(SimpleXMLElement)#%d (1) {
206  ["elem111"]=>
207  object(SimpleXMLElement)#%d (1) {
208    ["elem1111"]=>
209    object(SimpleXMLElement)#%d (0) {
210    }
211  }
212}
213===sxe->elem11->elem111
214bool(true)
215bool(true)
216int(1)
217object(SimpleXMLElement)#%d (1) {
218  ["elem1111"]=>
219  object(SimpleXMLElement)#%d (0) {
220  }
221}
222===sxe->elem11->elem111->elem1111
223bool(true)
224bool(true)
225int(1)
226object(SimpleXMLElement)#%d (0) {
227}
228===sxe->elem22
229bool(false)
230bool(false)
231object(SimpleXMLElement)#%d (0) {
232}
233===sxe->elem22->elem222
234bool(false)
235bool(false)
236NULL
237===sxe->elem22->attr22
238bool(false)
239bool(false)
240NULL
241===sxe->elem22["attr22"]
242bool(false)
243bool(false)
244NULL
245