xref: /PHP-8.0/ext/simplexml/tests/014b.phpt (revision a555cc0b)
1--TEST--
2SimpleXML: adding/removing attributes (second)
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   <person name="Boe"></person>
11</people>
12EOF;
13
14$people = simplexml_load_string($xml);
15var_dump($people->person[0]['name']);
16var_dump($people->person[1]['age']);
17$person = $people->person[1];
18$person['name'] = "XXX";
19var_dump($people->person[1]['name']);
20$people->person[1]['age'] = 30;
21var_dump($people->person[1]['age']);
22echo "---Unset:---\n";
23unset($people->person[1]['age']);
24echo "---Unset?---\n";
25var_dump($people->person[1]['age']);
26var_dump(isset($people->person[1]['age']));
27echo "---Unsupported---\n";
28$people->person[1]['age'] += 5;
29var_dump($people->person[1]['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---
50object(SimpleXMLElement)#%d (1) {
51  [0]=>
52  string(1) "5"
53}
54