|
DOMDocument::registerNodeClassRegister extended class used to create base node type Description
public bool DOMDocument::registerNodeClass(string
$baseClass , stringnull $extendedClass )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. Caution
The constructor of the objects of the registered node classes is not called. Parameters
Return Values
Returns Examples
Example #1 Adding a new method to DOMElement to ease our code
The above example will output: <?xml version="1.0"?> <root><child foo="bar"/></root>
Example #2 Retrieving elements as custom class
The above example will output: string(9) "myElement" text in child
Example #3 Retrieving owner document When instantiating a custom DOMDocument the ownerDocument property will refer to the instantiated class. However, if all references to that class are removed, it will be destroyed and new DOMDocument will be created instead. For that reason you might use DOMDocument::registerNodeClass with DOMDocument
The above example will output: string(13) "MyDOMDocument" string(11) "DOMDocument" string(18) "MyOtherDOMDocument" string(18) "MyOtherDOMDocument"
Example #4 Custom objects are transient Caution
Objects of the registered node classes are transient, i.e. they are destroyed when they are no longer referenced from PHP code, and recreated when being retrieved again. That implies that custom property values will be lost after recreation.
The above example will output: modified value default value |