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