Re: Proposal: $options argument for SimpleXMLElement::asXML
| From: | Rowan Tommins | Date: | Sun, 10 Sep 2023 13:35:24 +0000 |
| Subject: | Re: Proposal: $options argument for SimpleXMLElement::asXML | ||
| References: | 1 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-121029@lists.php.net to get a copy of this message | ||
On 9 September 2023 21:05:37 BST, Niels Dossche <dossche.niels@gmail.com> wrote:
>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:
1) 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.
2) 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]