Fix simplexml_import_dom() parameter type on PHP 8.4 - #6290
Merged
ondrejmirtes merged 1 commit intoAug 27, 2026
Conversation
PHP 8.4 widened the first parameter to `object`, so that the function
accepts the classes of the new DOM API next to `DOMNode`:
// PHP 8.3
function simplexml_import_dom(SimpleXMLElement|DOMNode $node, ?string $class_name = SimpleXMLElement::class): ?SimpleXMLElement {}
// PHP 8.4
function simplexml_import_dom(object $node, ?string $class_name = SimpleXMLElement::class): ?SimpleXMLElement {}
The map still declares `DOMNode` for every version. As a result, PHPStan
reports a false positive when the argument is a `Dom\Node`:
Parameter #1 $node of function simplexml_import_dom expects DOMNode, Dom\Node given.
Versions below 8.4 keep the previous type.
Member
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PHP 8.4 widened the first parameter of
simplexml_import_dom()toobject:PHP-8.4and not inPHP-8.3.The upstream reasoning, quoted from that commit message:
resources/functionMap.phpstill declaresDOMNodefor every version, so PHPStan reports a false positive for aDom\Nodeargument:The code is correct —
simplexml_import_dom()accepts aDom\Nodeat runtime on PHP 8.4 and 8.5.This adds the 8.4 signature to
functionMap_php84delta.php. Versions below 8.4 keep the previous type, so a non-DOM argument is still reported there.Verification
phpVersion: 80400, the example above reports the error before the change and no error after it.phpVersion: 80300,simplexml_import_dom(new stdClass())is still reported.tests/PHPStan/Reflection/SignatureMap/passes (2844 tests).Note
objectis deliberately open-ended upstream, so a closed union such asDOMNode|Dom\Node|SimpleXMLElementwould reject valid arguments from extensions that register their own node types. That is why this mirrors php-src rather than narrowing.Separately, the pre-8.4 entry omits
SimpleXMLElement, which the 8.0–8.3 stubs allow. I left that alone to keep this change focused; glad to send it as its own PR.Claude