ZF-3950: Zend_Dom_Query should remember its internal DOMDocument object
Currently every call to Zend_Dom_Query::queryXpath() results in a completely new DOMDocument object being created, regardless of whether or not the underlying document string has changed. This means that the same node retrieved by two separate queries is not actually the same node, making it difficult to do comparisons.
$string = '
first itemsecond item'; $queryObject = new Zend_Dom_Query($string); // Retrieve the first list item once. $firstQueryResult = $queryObject->query('li'); $firstItemFromFirstQuery = current($firstQueryResult); // Retrieve the first list item again. $secondQueryResult = $queryObject->query('li'); $firstItemFromSecondQuery = current($secondQueryResult); echo (integer)($firstItemFromFirstQuery->isSameNode($firstItemFromSecondQuery));
The result I'd like to see here is 1 (true), but the actual result is 0 (false).
In order to make this work the way I was hoping, Zend_Dom_Query would need to avoid re-creating the DOMDocument object with each query, instead storing it internally and using it again later.
One downside of this approach is that the contents of $_document might not necessarily reflect the contents of the internally-stored DOMDocument object, if that object is modified by outside code.