1--TEST-- 2SimpleXML: modifying attributes of singular subnode 3--EXTENSIONS-- 4simplexml 5--FILE-- 6<?php 7$xml =<<<EOF 8<people> 9 <person name="Joe"></person> 10</people> 11EOF; 12 13$people = simplexml_load_string($xml); 14var_dump($people->person['name']); 15$people->person['name'] = $people->person['name'] . 'Foo'; 16var_dump($people->person['name']); 17$people->person['name'] .= 'Bar'; 18var_dump($people->person['name']); 19 20echo "---[0]---\n"; 21 22$people = simplexml_load_string($xml); 23var_dump($people->person[0]['name']); 24$people->person[0]['name'] = $people->person[0]['name'] . 'Foo'; 25var_dump($people->person[0]['name']); 26$people->person[0]['name'] .= 'Bar'; 27var_dump($people->person[0]['name']); 28 29?> 30--EXPECTF-- 31object(SimpleXMLElement)#%d (1) { 32 [0]=> 33 string(3) "Joe" 34} 35object(SimpleXMLElement)#%d (1) { 36 [0]=> 37 string(6) "JoeFoo" 38} 39object(SimpleXMLElement)#%d (1) { 40 [0]=> 41 string(9) "JoeFooBar" 42} 43---[0]--- 44object(SimpleXMLElement)#%d (1) { 45 [0]=> 46 string(3) "Joe" 47} 48object(SimpleXMLElement)#%d (1) { 49 [0]=> 50 string(6) "JoeFoo" 51} 52object(SimpleXMLElement)#%d (1) { 53 [0]=> 54 string(9) "JoeFooBar" 55} 56