Let’s say you have a page that has multiple ( 12 ) invocations of this innerHTML function:
<?php
function innerHTML($node){
$doc = new DOMDocument();
foreach ($node->childNodes as $child)
$doc->appendChild($doc->importNode($child, true));
return $doc->saveHTML();
}
This would result in 12 DOMDocuments being made. Would it be worth it to save a reference to 1 DOMDocument and constantly clean it out per usage? If so, what would be the most efficient method of cleaning it?
I don’t think there’s any performance issues;
DOMDocumentisn’t parsing any XML upon creation. The most processing intensive operation in the whole thing I think issaveHTML(), so you wouldn’t save anything by using the sameDOMDocument.Destroying the object and creating a new one is likely more efficient than keeping a global variable and emptying it upon every use.