Skip to content

Return type of DOMNode::appendChild() should match the $node argument #9200

@derrabus

Description

@derrabus

Bug report

DOMNode::appendChild() returns the appended child which means that if I pass a DOMElement to that method, I can be certain that a DOMElement is returned by it. However, PHPStan does not recognize that and assumes that an instance of any DOMNode subclass can be returned.

Code snippet that reproduces the problem

function appendElement(DOMElement $element, DOMElement $to): DOMElement
{
	return $to->appendChild($element);
}

https://phpstan.org/r/4fb72139-58a8-434c-bee8-6cc651dfac65

Expected output

No error.

Did PHPStan help you today? Did it make you happy in any way?

Of course it did!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions