Skip to content
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

[RFC] Add simplexml_load_stream(), HTMLDocument::createFromStream(), XMLDocument::createFromStream() #17522

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

nielsdos
Copy link
Member

@nielsdos nielsdos commented Jan 19, 2025

RFC text to be written, WIP
Adds functionality to load XML/HTML from an already opened stream.

@nielsdos
Copy link
Member Author

cc @veewee @theseer maybe this is of interest for you

@frederikbosch
Copy link
Contributor

This an interesting feature (again). Another method I would love to see - which is very close to this PR - is XSLTProcessor::transformToStream. In that case XSLTProcessor::transformToUri would become a simplified version of the new transformToStream method.

@veewee veewee mentioned this pull request Jan 29, 2025
1 task
@nielsdos
Copy link
Member Author

Hi Frederik

That makes sense, and shouldn't be hard at all to add.
Something like public XSLTProcessor::transformToStream(object $document, /*resource*/ $stream): int should do.
The return value is up to debate I suppose. transformToUri returns an int that gives the number of written bytes on success, and -1 on failure. While transformToXml returns false or null on error, confusingly. We aren't really a fan of int|false returns any more because of the coercion between 0 and false when doing a == comparison. So I suppose in the exceptional case where no output could be generated an exception should be thrown. Feel free to give your opinion.

@frederikbosch
Copy link
Contributor

Not a fan of int|falseeither. I'd prefer an exception when the method fails. So void would be sufficient. When one needs to know the number of bytes written, one could check the size of the stream before and after the operation.

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.

2 participants