Freitag, 11. Dezember 2015

Note to self:: Don't use SimpleXmlElement if you have to change the XML's contents.

In PHP, if you really HAVE to do php - never ever EVER succumb to temptation and use a SimpleXMLElement for CHANGING the XML.

It seems to have methods for doing so, but believe me, they just don't work.

You'll end up doing crazy stuff like this:

         $xml2 = self::sortArticlesByFileNames($xml);
         $xml = simplexml_load_string($xml2->asXML());

And then, of course, you have to return $xml, so if you are already returning something else, you'll end up with

        list($xml, $whatever) = doStuff($xml);

for every single function that will change the xml.

Blargh.

In fact, probably, it's better to simply refuse to use SimpleXmlElement at all. It stinks.

Just. Don't. Do it.

You have been warned.