function hasParent($tag = null, $recursive = false)
{
if ($this->parent !== null) {
if ($tag === null) {
return true;
} elseif (is_string($tag)) {
return $this->parent->tag === $tag || $recursive && $this->parent->hasParent($tag);
} elseif (is_object($tag)) {
return $this->parent === $tag || $recursive && $this->parent->hasParent($tag);
}
}
return false;
}