xref: /PHP-8.2/ext/simplexml/tests/015.phpt (revision 7f2f0c00)
1--TEST--
2SimpleXML: accessing singular subnode as array
3--EXTENSIONS--
4simplexml
5--FILE--
6<?php
7$xml =<<<EOF
8<people>
9   <person name="Joe"></person>
10</people>
11EOF;
12
13$xml2 =<<<EOF
14<people>
15   <person name="Joe"></person>
16   <person name="Boe"></person>
17</people>
18EOF;
19
20$people = simplexml_load_string($xml);
21var_dump($people->person['name']);
22var_dump($people->person[0]['name']);
23//$people->person['name'] = "XXX";
24//var_dump($people->person['name']);
25//var_dump($people->person[0]['name']);
26//$people->person[0]['name'] = "YYY";
27//var_dump($people->person['name']);
28//var_dump($people->person[0]['name']);
29//unset($people->person[0]['name']);
30//var_dump($people->person['name']);
31//var_dump($people->person[0]['name']);
32//var_dump(isset($people->person['name']));
33//var_dump(isset($people->person[0]['name']));
34$people = simplexml_load_string($xml2);
35var_dump($people->person[0]['name']);
36var_dump($people->person[1]['name']);
37?>
38--EXPECTF--
39object(SimpleXMLElement)#%d (1) {
40  [0]=>
41  string(3) "Joe"
42}
43object(SimpleXMLElement)#%d (1) {
44  [0]=>
45  string(3) "Joe"
46}
47object(SimpleXMLElement)#%d (1) {
48  [0]=>
49  string(3) "Joe"
50}
51object(SimpleXMLElement)#%d (1) {
52  [0]=>
53  string(3) "Boe"
54}
55