When creating a DOMDocument with DOMImplementation::createDocument(), you can specify a doctype as the third argument in the constructor. This doctype then gets “tied” to the document and you can retrieve it later with $document->doctype.
However, this is a read-only attribute (unlike encoding and version!).
Is there any way to change the doctype property of an existing DOMDocument object?
The only workaround I can think of is to create a new DOMDocument with the new doctype, and import then copy across the contents from the old one.
It also seems possible to call $document->loadXML() again even if the document is already populated. It wipes the document and regenerates it, but it is a way of changing the doctype variable on an existing object, and the new doctype does have an HTML representation unlike in my other solution.