Skip to content

Fix dom_import_simplexml() return type #3882

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 6 commits into from
Oct 19, 2024
Merged

Fix dom_import_simplexml() return type #3882

merged 6 commits into from
Oct 19, 2024

Conversation

cmb69
Copy link
Member

@cmb69 cmb69 commented Oct 17, 2024

@cmb69 cmb69 requested a review from nielsdos as a code owner October 17, 2024 21:24
@nielsdos
Copy link
Member

nielsdos commented Oct 17, 2024

The documentation of this function is also a bit whack...

Description:

This function takes the node node of class SimpleXML and makes it into a DOMElement node. This new object can then be used as a native DOMElement node.

This is inaccurate now

Return values:

The DOMElement node added.

What ??? What does added even mean here?

cmb69 and others added 2 commits October 17, 2024 23:49
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
@cmb69
Copy link
Member Author

cmb69 commented Oct 17, 2024

What ??? What does added even mean here?

Indeed, makes no sense, so updated. (a bit sad, though, since it would have had its 20th birthday in a couple of weeks ;)

Before updating/improving/fixing the description, could you please have a look at the implementation of dom_import_simplexml_common():

https://github.com/php/php-src/blob/42e179ef9dc7f5b8cf6f1135c6be8e7ffe4aa5cb/ext/dom/php_dom.c#L566-L570

Is it really okay to cast an arbitrary object to a php_libxml_node_object?

@nielsdos
Copy link
Member

Note that php_libxml_import_node will fail if the object is not actually an xml object.
I suppose it would be cleaner to check failure of php_libxml_import_node first and only then do the cast, but I don't think the current ordering hurts.

@cmb69
Copy link
Member Author

cmb69 commented Oct 18, 2024

Ah, I've overlooked php_libxml_import_node!

I've pushed a further commit regarding the function and the parameter descriptions. However, it seems to me that not only SimpleXMLElements can be imported, but rather arbitrary objects which have been registered with libxml. Might be worth to document that at some time.

@nielsdos
Copy link
Member

Indeed it's broader than simplexml. However, in practice only DOM & simplexml register handlers to be able to do it.
Also a small nit on wording: you used "convert", but it's not actually converting in the sense that it's a clone; they're working on the same xml nodes so it's more like creating a "view". i.e. changes you make via dom are gonna be visible in simplexml and vice versa.

@cmb69
Copy link
Member Author

cmb69 commented Oct 18, 2024

Thanks for the clarification! I tried to improve the wording, and added a respective example.

@cmb69 cmb69 requested a review from nielsdos October 18, 2024 21:50
@nielsdos
Copy link
Member

Thanks a lot!

@cmb69 cmb69 merged commit d92352f into php:master Oct 19, 2024
2 checks passed
@cmb69 cmb69 deleted the cmb/gh16473 branch October 19, 2024 20:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants