On 22/04/2024 21:53, Larry Garfield wrote: > On Mon, Apr 22, 2024, at 6:41 PM, Niels Dossche wrote: >> Hi internals >> >> I'm opening the discussion for my RFC "Add openStream() to >> XML{Reader,Writer}". >> RFC link: https://wiki.php.net/rfc/xmlreader_writer_streams >> >> Kind regards >> Niels > > This seems quite reasonable to me overall. My one question is regarding the > writer version. Why is that not a static method, too? I would have expected > that to be a "named constructor" just like the reader. > > --Larry Garfield
Hi Larry XMLReader already had these static methods that act as named constructors, but XMLWriter has no named constructors at the moment. The XMLWriter::openMemory() and XMLWriter::openUri() functions are instance methods that must be called after doing "new XMLWriter". If these two existing functions were static methods instead, I would've made XMLWriter::openStream() static too. So IOW, for consistency I followed the model of the existing XMLWriter methods. While it is possible to do the magic trick that XMLReader uses to have the open methods on XMLWriter both static and non-static, this is quite hacky and was only done to XMLReader for BC reasons. Kind regards Niels