xref: /PHP-8.1/ext/simplexml/tests/014a.phpt (revision 7f2f0c00)
1--TEST--
2SimpleXML: adding/removing attributes (single)
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[0]['name']);
15var_dump($people->person[0]['age']);
16$person = $people->person[0];
17$person['name'] = "XXX";
18var_dump($people->person[0]['name']);
19$people->person[0]['age'] = 30;
20var_dump($people->person[0]['age']);
21echo "---Unset:---\n";
22unset($people->person[0]['age']);
23echo "---Unset?---\n";
24var_dump($people->person[0]['age']);
25var_dump(isset($people->person[0]['age']));
26echo "---Unsupported---\n";
27var_dump($people->person[0]['age']);
28$people->person['age'] += 5;
29var_dump($people->person[0]['age']);
30?>
31--EXPECTF--
32object(SimpleXMLElement)#%d (1) {
33  [0]=>
34  string(3) "Joe"
35}
36NULL
37object(SimpleXMLElement)#%d (1) {
38  [0]=>
39  string(3) "XXX"
40}
41object(SimpleXMLElement)#%d (1) {
42  [0]=>
43  string(2) "30"
44}
45---Unset:---
46---Unset?---
47NULL
48bool(false)
49---Unsupported---
50NULL
51object(SimpleXMLElement)#%d (1) {
52  [0]=>
53  string(1) "5"
54}
55