A->b->c might exist but c might not exist. How do I check it?
I use a helper function to check if a node is a valid node provided as a parameter in function.
private static function isValidNode($node) {
return isset($node) && $node instanceof SimpleXMLElement && !empty($node);
}
Usage example:
public function getIdFromNode($node) {
if (!self::isValidNode($node)) {
return 0;
}
return (int)$node['id'];
}