dom003.phpt 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. --TEST--
  2. Test 3: Exception Test
  3. --SKIPIF--
  4. <?php require_once('skipif.inc'); ?>
  5. --FILE--
  6. <?php
  7. $dom = new domdocument;
  8. $dom->load(dirname(__FILE__)."/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. ["file":protected]=>
  31. string(%d) "%sdom003.php"
  32. ["line":protected]=>
  33. int(8)
  34. ["trace":"Exception":private]=>
  35. array(1) {
  36. [0]=>
  37. array(6) {
  38. ["file"]=>
  39. string(%d) "%sdom003.php"
  40. ["line"]=>
  41. int(8)
  42. ["function"]=>
  43. string(11) "appendChild"
  44. ["class"]=>
  45. string(7) "DOMNode"
  46. ["type"]=>
  47. string(2) "->"
  48. ["args"]=>
  49. array(1) {
  50. [0]=>
  51. DOMElement
  52. }
  53. }
  54. }
  55. ["previous":"Exception":private]=>
  56. NULL
  57. ["code"]=>
  58. int(3)
  59. }
  60. --- Don't catch exception with try/catch
  61. Fatal error: Uncaught exception 'DOMException' with message '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