]> granicus.if.org Git - php/commitdiff
Merge from Trunk
authorChristian Stocker <chregu@php.net>
Thu, 1 Sep 2011 13:42:45 +0000 (13:42 +0000)
committerChristian Stocker <chregu@php.net>
Thu, 1 Sep 2011 13:42:45 +0000 (13:42 +0000)
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

NEWS
ext/simplexml/simplexml.c
ext/simplexml/tests/008.phpt

diff --git a/NEWS b/NEWS
index 09d88dd7ff16140ce9f608457eb057c03aebc84d..4dceba2228670bcb0012c9440f4600c73afe8781 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,12 @@ PHP                                                                        NEWS
   . Don't set $_SERVER['HTTPS'] on unsecure connection (bug #55403). (Uwe
     Schindler)
 
+- SimpleXML:
+  . Reverted the SimpleXML->query() behaviour to returning empty arrays
+    instead of false when no nodes are found as it was since 5.3.3 
+    (bug #48601). (chregu, rrichards)
+    
+
 23 Aug 2011, PHP 5.3.8
 
 - Core:
index 9bb9af1a85c6154063a02a7fc04da788563b26e5..c2697ba170772ffb7243f68355adc0eec2d24313 100644 (file)
@@ -1264,8 +1264,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) {
@@ -1286,8 +1287,6 @@ SXE_METHOD(xpath)
                                add_next_index_zval(return_value, value);
                        }
                }
-       } else {
-               RETVAL_FALSE;
        }
 
        xmlXPathFreeObject(retval);
index 4fda204a2fe3030a176c80fa491354785e26eba4..8734ba4a46312c9b05e50ce18be61d550124e1db 100644 (file)
@@ -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)