Avoid "Trying to get property of non-object"

This commit is contained in:
Michael 2018-07-08 11:46:05 +00:00
parent 3e797547a3
commit 7d6933c898
4 changed files with 68 additions and 54 deletions

View file

@ -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;
}
}