Extending DOMNode

Sometimes you may think: Wouldn’t it be cool if I can extend DOMNode and since all other functions extend DOMNode, my custon functions will be available in every element?

The bad news, it will not work for DOMNode, but the other elements which extend from it.

Why is that?

PHP offers a special function, which can be used to extend the DOM, its called registerNodeClass and is located in DOMDocument.


This method allows you to register your own extended DOM class to be used afterward by the PHP DOM extension.

This method is not part of the DOM standard.

Here is the example from PHP.net:

If you want to replace a function with your own, your function has to extend the function you want to replace.

So what? What is the problem with DOMNode? –>