dom003.phpt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. --TEST--
  2. Test 3: Exception Test
  3. --EXTENSIONS--
  4. dom
  5. --FILE--
  6. <?php
  7. $dom = new domdocument;
  8. $dom->load(__DIR__."/book.xml");
  9. $rootNode = $dom->documentElement;
  10. print "--- Catch exception with try/catch\n";
  11. try {
  12. $rootNode->appendChild($rootNode);
  13. } catch (domexception $e) {
  14. ob_start();
  15. var_dump($e);
  16. $contents = ob_get_contents();
  17. ob_end_clean();
  18. echo preg_replace('/object\(DOMElement\).+\{.*?\}/s', 'DOMElement', $contents);
  19. }
  20. print "--- Don't catch exception with try/catch\n";
  21. $rootNode->appendChild($rootNode);
  22. ?>
  23. --EXPECTF--
  24. --- Catch exception with try/catch
  25. object(DOMException)#%d (%d) {
  26. ["message":protected]=>
  27. string(23) "Hierarchy Request Error"
  28. ["string":"Exception":private]=>
  29. string(0) ""
  30. ["code"]=>
  31. int(3)
  32. ["file":protected]=>
  33. string(%d) "%sdom003.php"
  34. ["line":protected]=>
  35. int(8)
  36. ["trace":"Exception":private]=>
  37. array(1) {
  38. [0]=>
  39. array(6) {
  40. ["file"]=>
  41. string(%d) "%sdom003.php"
  42. ["line"]=>
  43. int(8)
  44. ["function"]=>
  45. string(11) "appendChild"
  46. ["class"]=>
  47. string(7) "DOMNode"
  48. ["type"]=>
  49. string(2) "->"
  50. ["args"]=>
  51. array(1) {
  52. [0]=>
  53. DOMElement
  54. }
  55. }
  56. }
  57. ["previous":"Exception":private]=>
  58. NULL
  59. }
  60. --- Don't catch exception with try/catch
  61. Fatal error: Uncaught DOMException: Hierarchy Request Error in %sdom003.php:%d
  62. Stack trace:
  63. #0 %sdom003.php(%d): DOMNode->appendChild(Object(DOMElement))
  64. #1 {main}
  65. thrown in %sdom003.php on line %d