DOMNode_hasChildNodes_basic.phpt 830 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. --TEST--
  2. Test whether a node has child nodes: hasChildNodes()
  3. --EXTENSIONS--
  4. dom
  5. --FILE--
  6. <?php
  7. /* Create an XML document
  8. * with structure
  9. * <book>
  10. * <title>This is the title</title>
  11. * </book>
  12. * Check for child nodes of the <book>, <title> and This is the title
  13. *
  14. */
  15. $doc = new DOMDocument();
  16. $root = $doc->createElement('book');
  17. $doc->appendChild($root);
  18. $title = $doc->createElement('title');
  19. $root->appendChild($title);
  20. $text = $doc->createTextNode('This is the title');
  21. $title->appendChild($text);
  22. echo "Root has child nodes: ";
  23. var_dump($root->hasChildNodes());
  24. echo "Title has child nodes: ";
  25. var_dump($title->hasChildNodes());
  26. echo "Text has child nodes: ";
  27. var_dump($text->hasChildNodes());
  28. ?>
  29. --EXPECT--
  30. Root has child nodes: bool(true)
  31. Title has child nodes: bool(true)
  32. Text has child nodes: bool(false)