xref: /PHP-8.3/ext/simplexml/tests/bug38406.phpt (revision 7f2f0c00)
1--TEST--
2Bug #38406 (crash when assigning objects to SimpleXML attributes)
3--EXTENSIONS--
4simplexml
5--FILE--
6<?php
7
8$item = new SimpleXMLElement('<something />');
9$item->attribute = 'something';
10var_dump($item->attribute);
11
12$item->otherAttribute = $item->attribute;
13var_dump($item->otherAttribute);
14
15$a = array();
16
17try {
18    $item->$a = new stdclass;
19} catch (TypeError $exception) {
20    echo $exception->getMessage() . "\n";
21}
22
23echo "Done\n";
24?>
25--EXPECTF--
26object(SimpleXMLElement)#%d (1) {
27  [0]=>
28  string(9) "something"
29}
30object(SimpleXMLElement)#%d (1) {
31  [0]=>
32  string(9) "something"
33}
34
35Warning: Array to string conversion in %s on line %d
36It's not possible to assign a complex type to properties, stdClass given
37Done
38