I want to convert a DOMNode
object from a call to getElementsByTagName()
to a DOMElement
in order to access methods like getElements
If anyone is looking for a more elegant solution in IntelliJ/PHPStorm. I managed to solve the issue like this:
private function doSomething(DOMNode $child){
if(!$child instanceof DOMElement)
throw new Exception('DOMElement expected but got something else.');
$attr = $child->getAttribute('attr'); //recognized by PHPStorm now as DOMElement
/* and more code */
}
All my code corretly assumes DOMNode which is de super class of DOMElement but also DOMComment etc. When I need DOMElement to use getAttribute
for example, then I add above check.