On 9 September 2023 21:05:37 BST, Niels Dossche <dossche.ni...@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]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to