DiDom\Element::parent PHP Method

parent() public method

public parent ( ) : Element | Document | null
return Element | Document | null
    public function parent()
    {
        if ($this->node->parentNode === null) {
            return null;
        }
        if ($this->node->parentNode instanceof \DOMDocument) {
            return new Document($this->node->parentNode);
        }
        return new Element($this->node->parentNode);
    }

Usage Example

示例#1
0
 public function testParentWithoutOwner()
 {
     $element = new Element(new \DOMElement('span', 'hello'));
     $this->assertNull($element->parent());
 }