xref: /PHP-5.6/ext/simplexml/tests/015.phpt (revision b6321d4e)
1--TEST--
2SimpleXML: accessing singular subnode as array
3--SKIPIF--
4<?php if (!extension_loaded("simplexml")) print "skip"; ?>
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===DONE===
39--EXPECTF--
40object(SimpleXMLElement)#%d (1) {
41  [0]=>
42  string(3) "Joe"
43}
44object(SimpleXMLElement)#%d (1) {
45  [0]=>
46  string(3) "Joe"
47}
48object(SimpleXMLElement)#%d (1) {
49  [0]=>
50  string(3) "Joe"
51}
52object(SimpleXMLElement)#%d (1) {
53  [0]=>
54  string(3) "Boe"
55}
56===DONE===
57