psalm
psalm copied to clipboard
regression: ownerDocument can be null
Back in 2020 to resolve issue #3081 a change was made to incorporate the fact that DOMNode::ownerDocument
can be null. This was effectively reverted with PR #10619.
This reverting change is technically wrong and not following the actual implementation in PHP.
The example linked in the PR (https://3v4l.org/tWoCc) about PHP enforcing the non-nullable type is misleading/incorrect, as a modified, even simpler, example demonstrates: https://3v4l.org/fGc7t
In other words: The ownerDocument
-Property can very much (still) be null. Whether or not this is a desirable behavior is a different story.
Hey @theseer, can you reproduce the issue on https://psalm.dev? These will be used as phpunit tests when implementing the feature or fixing this bug.
https://psalm.dev/r/cfd852bd7a
I found these snippets:
https://psalm.dev/r/cfd852bd7a
<?php
$node = new DOMElement('foo');
assert($node->ownerDocument instanceof DOMDocument);
Psalm output (using commit ef3b018):
ERROR: RedundantCondition - 4:1 - Type DOMDocument for $node->ownerDocument is always DOMDocument
The official stubs show that @theseer is right: https://github.com/php/php-src/blob/PHP-8.3.5/ext/dom/php_dom.stub.php#L335