mirror of
https://github.com/php/php-src.git
synced 2024-12-12 11:23:53 +08:00
e1813b69c5
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
49 lines
882 B
PHP
49 lines
882 B
PHP
--TEST--
|
|
SimpleXML: XPath
|
|
--SKIPIF--
|
|
<?php if (!extension_loaded("simplexml")) print "skip"; ?>
|
|
--FILE--
|
|
<?php
|
|
|
|
$xml =<<<EOF
|
|
<?xml version='1.0'?>
|
|
<!DOCTYPE sxe SYSTEM "notfound.dtd">
|
|
<sxe id="elem1">
|
|
<elem1 attr1='first'>
|
|
<!-- comment -->
|
|
<elem2>
|
|
<elem3>
|
|
<elem4>
|
|
<?test processing instruction ?>
|
|
</elem4>
|
|
</elem3>
|
|
</elem2>
|
|
</elem1>
|
|
</sxe>
|
|
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) {
|
|
[0]=>
|
|
object(SimpleXMLElement)#%d (1) {
|
|
["test"]=>
|
|
object(SimpleXMLElement)#%d (0) {
|
|
}
|
|
}
|
|
}
|
|
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)
|