Hacking the DOM Object Hierarchy
The PHP DOM extension provides an object hierarchy that allows you to manipulate an XML or HTML document in a safe and structured way. Some of that object hierarchy is...
The PHP DOM extension provides an object hierarchy that allows you to manipulate an XML or HTML document in a safe and structured way. Some of that object hierarchy is even extensible.
During my work on the AMP PHP toolbox, I created a whole abstraction layer on top of the DOM hierarchy to both fix all sorts of shortcomings or bugs, and to add convenience functionality that makes the rest of the code cleaner or more resilient.
In this talk, I’ll cover how the extension mechanisms work, where they don’t actually work at all, and what we did to produce a somewhat coherent abstraction layer that lets you provide a specialized API to modify documents.
Some of the use cases covered:
- abstractions providing clean APIs
- optimizations that cache state behind the scenes
- stronger type-hinting – automatic transcoding to UTF-8
- fixes and polyfills for
libxmlbugs and compatibility issues - convenient access to and automatic generation of expected elements