xref: /PHP-7.1/ext/simplexml/tests/014.phpt (revision 7af945e2)
1--TEST--
2SimpleXML: adding/removing attributes (direct)
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['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===DONE===
33--EXPECTF--
34object(SimpleXMLElement)#%d (1) {
35  [0]=>
36  string(3) "Joe"
37}
38NULL
39object(SimpleXMLElement)#%d (1) {
40  [0]=>
41  string(3) "XXX"
42}
43object(SimpleXMLElement)#%d (1) {
44  [0]=>
45  string(2) "30"
46}
47---Unset:---
48---Unset?---
49NULL
50bool(false)
51---Unsupported---
52object(SimpleXMLElement)#%d (1) {
53  [0]=>
54  string(2) "30"
55}
56object(SimpleXMLElement)#%d (1) {
57  [0]=>
58  string(2) "35"
59}
60===DONE===
61