innerNode; $doc = ($innerNodeResolver instanceof \DOMDocument) ? $innerNodeResolver : $innerNodeResolver->ownerDocument; foreach ($m as $prefix) { $prefix = $prefix[1]; if ($namespace = $resolver->lookupNamespaceURI($prefix)) { $doc->xpath->registerNamespace($prefix, $namespace); } } set_error_handler([ $this, 'xpathErrorHandler' ]); $doc->xpath->evaluate($expression); restore_error_handler(); } else { // Test the expression by attempting to run it on an empty document. PHP's DOM // XPath incorrectly issues a warnings rather than exceptions when expressions // are incorrect, so we must use a custom error handler here to "catch" it and // throw an exception in its place. set_error_handler([ $this, 'xpathErrorHandler' ]); $xpath = new \DOMXPath(new \DOMDocument()); $xpath->evaluate($expression); restore_error_handler(); } if ($this->__xpathException) { $e = $this->__xpathException; $this->__xpathException = null; throw $e; } $this->expression = $expression; $this->resolver = $resolver; } public function evaluate(Node $contextNode, int $type = XPathResult::ANY_TYPE, ?XPathResult $result = null): XPathResult { return $this->xpathEvaluate($this->expression, $contextNode, $this->resolver, $type, $result); } }