Avoid "Trying to get property of non-object"
This commit is contained in:
@@ -431,4 +431,19 @@ class XML
|
||||
}
|
||||
return $x;
|
||||
}
|
||||
|
||||
public static function getFirstNodeValue($xpath, $element, $context = null)
|
||||
{
|
||||
$result = $xpath->evaluate($element, $context);
|
||||
if (!is_object($result)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$first_item = $result->item(0);
|
||||
if (!is_object($first_item)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $first_item->nodeValue;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user