toString_exceptions.phpt 1.6 KB

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