regsiter_node_class.phpt 965 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. --TEST--
  2. Test: registerNodeClass()
  3. --SKIPIF--
  4. <?php require_once('skipif.inc'); ?>
  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. print $attr->testit()."\n";
  29. ?>
  30. --EXPECTF--
  31. myElement
  32. HELLO Element
  33. myAttribute
  34. HELLO Attribute
  35. DOMAttr
  36. Fatal error: Call to undefined method DOMAttr::testit() in %s on line 25