1--TEST--
2DOMElement::className
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8class MyStringable {
9    public function __toString(): string {
10        throw new Exception("foo");
11    }
12}
13
14$dom = new DOMDocument();
15$dom->loadXML('<html/>');
16
17var_dump($dom->documentElement->className);
18$dom->documentElement->className = "hello & world<>";
19var_dump($dom->documentElement->className);
20$dom->documentElement->className = "";
21var_dump($dom->documentElement->className);
22$dom->documentElement->className = "é";
23var_dump($dom->documentElement->className);
24$dom->documentElement->className = "\0";
25var_dump($dom->documentElement->className);
26$dom->documentElement->className = 12345;
27var_dump($dom->documentElement->className);
28try {
29    $dom->documentElement->className = new MyStringable();
30} catch (Throwable $e) {
31    echo "Error: ", $e->getMessage(), "\n";
32}
33var_dump($dom->documentElement->className);
34echo $dom->saveXML();
35
36?>
37--EXPECT--
38string(0) ""
39string(15) "hello & world<>"
40string(0) ""
41string(2) "é"
42string(0) ""
43string(5) "12345"
44Error: foo
45string(5) "12345"
46<?xml version="1.0"?>
47<html class="12345"/>
48