1--TEST--
2Handling of exceptions during __toString
3--EXTENSIONS--
4dom
5--FILE--
6<?php
7
8class BadStr {
9    public function __toString() {
10        throw new Exception("Exception");
11    }
12}
13
14$badStr = new BadStr;
15
16$doc = new DOMDocument();
17$doc->loadXML(
18    '<root xmlns:ns="foo"><node attr="foo" /><node>Text</node><ns:node/><?pi foobar?></root>');
19
20try { $doc->encoding = $badStr; } catch (Exception $e) { echo "Exception\n"; }
21try { $doc->version = $badStr; } catch (Exception $e) { echo "Exception\n"; }
22try { $doc->documentURI = $badStr; } catch (Exception $e) { echo "Exception\n"; }
23$root = $doc->childNodes[0];
24
25$node = $root->childNodes[0];
26$attrs = $node->attributes;
27$attr = $attrs[0];
28try { $attr->value = $badStr; } catch (Exception $e) { echo "Exception\n"; }
29try { $attr->nodeValue = $badStr; } catch (Exception $e) { echo "Exception\n"; }
30
31$node2 = $root->childNodes[1];
32try { $node2->nodeValue = $badStr; } catch (Exception $e) { echo "Exception\n"; }
33try { $node2->textContent = $badStr; } catch (Exception $e) { echo "Exception\n"; }
34$data = $node2->childNodes[0];
35try { $data->data = $badStr; } catch (Exception $e) { echo "Exception\n"; }
36
37$node3 = $root->childNodes[2];
38try { $node3->prefix = $badStr; } catch (Exception $e) { echo "Exception\n"; }
39
40$pi = $root->childNodes[3];
41try { $pi->data = $badStr; } catch (Exception $e) { echo "Exception\n"; }
42
43echo $doc->saveXML();
44
45?>
46--EXPECT--
47Exception
48Exception
49Exception
50Exception
51Exception
52Exception
53Exception
54Exception
55Exception
56Exception
57<?xml version="1.0"?>
58<root xmlns:ns="foo"><node attr="foo"/><node>Text</node><ns:node/><?pi foobar?></root>
59