From: Christian Stocker Date: Wed, 31 Aug 2011 11:44:22 +0000 (+0000) Subject: simplexml->query returns empty array if no nodes were found X-Git-Tag: php-5.5.0alpha1~1425 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2ea8e386153bdd1769241f8fef13ebbf63651385;p=php simplexml->query returns empty array if no nodes were found and false if libxml thinks the xpath-expression was invalid. Behaves now the same like DomXPath and fixes Bug #48601 Adjusted a test to reflect that change --- diff --git a/ext/simplexml/simplexml.c b/ext/simplexml/simplexml.c index c7bada57c4..d05630c2c9 100644 --- a/ext/simplexml/simplexml.c +++ b/ext/simplexml/simplexml.c @@ -1294,8 +1294,9 @@ SXE_METHOD(xpath) result = retval->nodesetval; + array_init(return_value); + if (result != NULL) { - array_init(return_value); for (i = 0; i < result->nodeNr; ++i) { nodeptr = result->nodeTab[i]; if (nodeptr->type == XML_TEXT_NODE || nodeptr->type == XML_ELEMENT_NODE || nodeptr->type == XML_ATTRIBUTE_NODE) { @@ -1316,8 +1317,6 @@ SXE_METHOD(xpath) add_next_index_zval(return_value, value); } } - } else { - RETVAL_FALSE; } xmlXPathFreeObject(retval); diff --git a/ext/simplexml/tests/008.phpt b/ext/simplexml/tests/008.phpt index 4fda204a2f..8734ba4a46 100644 --- a/ext/simplexml/tests/008.phpt +++ b/ext/simplexml/tests/008.phpt @@ -25,7 +25,10 @@ EOF; $sxe = simplexml_load_string($xml); var_dump($sxe->xpath("elem1/elem2/elem3/elem4")); +//valid expression var_dump($sxe->xpath("***")); +//invalid expression +var_dump($sxe->xpath("**")); ?> --EXPECTF-- array(1) { @@ -36,4 +39,10 @@ array(1) { } } } +array(0) { +} + +Warning: SimpleXMLElement::xpath(): Invalid expression in %s on line %d + +Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in %s on line %d bool(false)