Hi internals
I came across https://bugs.php.net/bug.php?id=67387.
Passing the option in via the constructor doesn't work because the constructor only allows parser options.
We can implement support for options (such as LIBXML_NOXMLDECL, LIBXML_SAVE_NOEMPTYTAG) by adding an (optional) argument to the asXML function: ?int $options = 0
.
This would be a BC break, because userland classes extending from SimpleXMLElement and overriding asXML would have to change the signature of asXML.
It's not hard at all to implement this functionality, but I want to ask first if there's any opinions on this before I write up an RFC.
Thanks
Niels
Hi internals
I came across https://bugs.php.net/bug.php?id=67387.
Passing the option in via the constructor doesn't work because the constructor only allows parser options.
We can implement support for options (such as LIBXML_NOXMLDECL, LIBXML_SAVE_NOEMPTYTAG) by adding an (optional) argument to the asXML function:?int $options = 0
.
In principle, I agree that that makes a lot of sense.
This would be a BC break, because userland classes extending from SimpleXMLElement and overriding asXML would have to change the signature of asXML.
Ah, that's a pain. I can think of two solutions that avoid the BC break, but neither are great:
- Create a new method, e.g. asXmlWithOptions(). No BC break unless someone happens to have a method of that name on their sub-class, but an awkward name in the long-term.
- Allow output options on the constructor, and carry them forwards through instances until asXml() is called. No BC break, but not very intuitive.
Actually, it occurs to me that if you think of the options as stateful on the instance, a third option is to have a setOutputOptions() method to be called before asXml(). Still a bit clunky though.
Regards,
--
Rowan Tommins
[IMSoP]