Psalm: DOMDocument::appendChild returns input value where Psalm thinks its always a DOMNode

Created on 12 May 2018  路  5Comments  路  Source: vimeo/psalm

This makes Psalm think that it has neither setAttribute nor getAttribute methods, yet it has them.

$doc = new DOMDocument("1.0");
$node = $doc->createElement("foo");
$newnode = $doc->appendChild($node);
$newnode->setAttribute("bar", "baz");
var_dump($newnode->getAttribute('bar'));
var_dump(method_exists($newnode, 'getAttribute'));

All 5 comments

Ah, DOMNode really doesn't have those methods. But it looks like DomDocument::appendChild, contra the documentation, returns a DomElement

At least in some instances

Well, it appears that createElement() always returns what is given.

I'm closing this as a bogus because Psalm can't help it.

Yes it most certainly can :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

weirdan picture weirdan  路  4Comments

muglug picture muglug  路  3Comments

Ocramius picture Ocramius  路  3Comments

Pierstoval picture Pierstoval  路  3Comments

zerkms picture zerkms  路  3Comments