regsiter_node_class.phpt 963 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. --TEST--
  2. Test: registerNodeClass()
  3. --EXTENSIONS--
  4. dom
  5. --FILE--
  6. <?php
  7. class myAttribute extends DOMAttr {
  8. function testit() { return "HELLO Attribute"; }
  9. }
  10. class myElement extends DOMElement {
  11. function testit() { return "HELLO Element"; }
  12. }
  13. $doc = new DOMDocument();
  14. $doc->registerNodeClass('DOMAttr', 'myAttribute');
  15. $doc->registerNodeClass('DOMElement', 'myElement');
  16. $doc->appendChild(new DOMElement('root'));
  17. $root = $doc->documentElement;
  18. $root->setAttribute('a', 'a1');
  19. echo get_class($root), "\n";
  20. print $root->testit()."\n";
  21. $attr = $root->getAttributeNode('a');
  22. echo get_class($attr), "\n";
  23. print $attr->testit()."\n";
  24. unset($attr);
  25. $doc->registerNodeClass('DOMAttr', NULL);
  26. $attr = $root->getAttributeNode('a');
  27. echo get_class($attr), "\n";
  28. try {
  29. print $attr->testit()."\n";
  30. } catch (Error $e) {
  31. echo $e->getMessage();
  32. }
  33. ?>
  34. --EXPECT--
  35. myElement
  36. HELLO Element
  37. myAttribute
  38. HELLO Attribute
  39. DOMAttr
  40. Call to undefined method DOMAttr::testit()