Project

Profile

Help

Feature #4789

closed

Throw exceptions instead of silently returning null

Added by Peter Jan about 4 years ago. Updated almost 3 years ago.

Status:
Closed
Priority:
Normal
Category:
Documentation
Start date:
2020-10-08
Due date:
% Done:

100%

Estimated time:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Found in version:
1.2.1
Fixed in version:
11.1
SaxonC Languages:
SaxonC Platforms:
SaxonC Architecture:

Description

I'm trying to find the namespace of an XML file with:

$saxonProc = new SaxonProcessor();
$xPathProcessor = $saxonProc->newXPathProcessor();
$xPathProcessor->setContextFile($file->getPathname());
$item = $xPathProcessor->evaluateSingle('/*/namespace::*[name()=\'\']');

According to the documentation:

evaluateSingle(string $xpathStr)
Compile and evaluate an XPath expression whose result is expected to be a single item, with a given context item. The expression is supplied as a character string, and the result returned as an XdmItem.

So the return value is expected to be an XdmItem. However, when the expression could not be evaluated, it can also return null.

It would be great if exceptions can be thrown when these situations occur. (I expect these can be applied on other functions as well?), so these exceptions can be caught with a try-catch block. Now, the return type is not documented, but 'silently' returning a null value is also not desirable.

Please register to edit this issue

Also available in: Atom PDF