Skip to content

Commit e1813b6

Browse files
committed
Merge from Trunk
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
1 parent 3c15d50 commit e1813b6

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

NEWS

+6
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ PHP NEWS
2626
. Don't set $_SERVER['HTTPS'] on unsecure connection (bug #55403). (Uwe
2727
Schindler)
2828

29+
- SimpleXML:
30+
. Reverted the SimpleXML->query() behaviour to returning empty arrays
31+
instead of false when no nodes are found as it was since 5.3.3
32+
(bug #48601). (chregu, rrichards)
33+
34+
2935
23 Aug 2011, PHP 5.3.8
3036

3137
- Core:

ext/simplexml/simplexml.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -1264,8 +1264,9 @@ SXE_METHOD(xpath)
12641264

12651265
result = retval->nodesetval;
12661266

1267+
array_init(return_value);
1268+
12671269
if (result != NULL) {
1268-
array_init(return_value);
12691270
for (i = 0; i < result->nodeNr; ++i) {
12701271
nodeptr = result->nodeTab[i];
12711272
if (nodeptr->type == XML_TEXT_NODE || nodeptr->type == XML_ELEMENT_NODE || nodeptr->type == XML_ATTRIBUTE_NODE) {
@@ -1286,8 +1287,6 @@ SXE_METHOD(xpath)
12861287
add_next_index_zval(return_value, value);
12871288
}
12881289
}
1289-
} else {
1290-
RETVAL_FALSE;
12911290
}
12921291

12931292
xmlXPathFreeObject(retval);

ext/simplexml/tests/008.phpt

+9
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ EOF;
2525
$sxe = simplexml_load_string($xml);
2626

2727
var_dump($sxe->xpath("elem1/elem2/elem3/elem4"));
28+
//valid expression
2829
var_dump($sxe->xpath("***"));
30+
//invalid expression
31+
var_dump($sxe->xpath("**"));
2932
?>
3033
--EXPECTF--
3134
array(1) {
@@ -36,4 +39,10 @@ array(1) {
3639
}
3740
}
3841
}
42+
array(0) {
43+
}
44+
45+
Warning: SimpleXMLElement::xpath(): Invalid expression in %s on line %d
46+
47+
Warning: SimpleXMLElement::xpath(): xmlXPathEval: evaluation failed in %s on line %d
3948
bool(false)

0 commit comments

Comments
 (0)