Skip to content

Fix argument type of simplexml_import_dom #13170

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 18, 2024
Merged

Fix argument type of simplexml_import_dom #13170

merged 2 commits into from
Jan 18, 2024

Conversation

nielsdos
Copy link
Member

It needs to be "object".
This is because first- and third-party extension can register custom node types using php_libxml_register_export. So we don't know upfront what types can be expected.

This also changes the error to a ValueError, which is consistent with ext/xsl.

Sending this fix to master because of potential BC breaks.

It needs to be "object".
This is because first- and third-party extension can register custom
node types using `php_libxml_register_export`. So we don't know upfront
what types can be expected.

This also changes the error to a ValueError, which is consistent with
ext/xsl.
@@ -2567,7 +2567,7 @@ PHP_FUNCTION(simplexml_import_dom)
nodep = php_libxml_import_node(node);

if (!nodep) {
zend_argument_type_error(1, "must be of type SimpleXMLElement|DOMNode, %s given", zend_zval_value_name(node));
zend_argument_value_error(1, "must be a valid XML node");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this needs to be a value error, it is consistent with ext/xsl; but perhaps those should be type errors too instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having it be a type error probably makes more sense? I don't imagine it is possible to introduce an interface in ext/libxml that extensions that hook into need to implement?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having it be a type error probably makes more sense?

Alright, and change the error type for ext/xsl too?

I don't imagine it is possible to introduce an interface in ext/libxml that extensions that hook into need to implement?

It's possible to do this, but would need downstream changes and as such may need an RFC.
Actually it's a bit of a special case because this would only be useful for internal classes, unless we rework the importing mechanism.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd also vote for a TypeError

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, I pushed that as an extra commit to this PR.

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nielsdos nielsdos merged commit 4bd6356 into php:master Jan 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants