xref: /PHP-7.4/ext/simplexml/tests/012.phpt (revision d679f022)
1--TEST--
2SimpleXML: Attribute creation
3--SKIPIF--
4<?php
5	if (!extension_loaded('simplexml')) print 'skip';
6?>
7--FILE--
8<?php
9
10$xml =<<<EOF
11<?xml version="1.0" encoding="ISO-8859-1" ?>
12<foo/>
13EOF;
14
15$sxe = simplexml_load_string($xml);
16
17
18$sxe[""] = "warning";
19$sxe["attr"] = "value";
20
21echo $sxe->asXML();
22
23$sxe["attr"] = "new value";
24
25echo $sxe->asXML();
26
27$sxe[] = "error";
28
29__HALT_COMPILER();
30?>
31===DONE===
32--EXPECTF--
33Warning: main(): Cannot write or create unnamed attribute in %s012.php on line %d
34<?xml version="1.0" encoding="ISO-8859-1"?>
35<foo attr="value"/>
36<?xml version="1.0" encoding="ISO-8859-1"?>
37<foo attr="new value"/>
38
39Fatal error: Uncaught Error: Cannot create unnamed attribute in %s012.php:%d
40Stack trace:
41#0 {main}
42  thrown in %s012.php on line %d
43