xref: /PHP-7.2/ext/simplexml/tests/014a.phpt (revision 17ccbeec)
1--TEST--
2SimpleXML: adding/removing attributes (single)
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$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===DONE===
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---
51NULL
52object(SimpleXMLElement)#%d (1) {
53  [0]=>
54  string(1) "5"
55}
56===DONE===
57