DOMNode to DOMElement in php

后端 未结 5 1459
南旧
南旧 2021-02-13 20:15

I want to convert a DOMNode object from a call to getElementsByTagName() to a DOMElement in order to access methods like getElements

5条回答
  •  甜味超标
    2021-02-13 20:58

    I know this is mostly an annoying IDE problem.

    The reason is $DOMNodeList->item(0) witch returns a DOMNode ( or at least the IDE thinks so ).

    To fix this you will have to Extract out the $DOMDocument->getElementsByTagName( $tagName )->item($index) into a method of its own. In the DOCBlock you set the @return statement to DOMElement witch fixes the inspection problem.

    This Works at least in PHPStorm.

提交回复
热议问题