PHP bug + version dependency hell

I have discovered a bug in PHP 5.4.4: a simple XPATH does not work.

$xml = simplexml_load_string("<root><a/><b>text</b></root>");
$node = $xml->xpath("/root/b")[0]; // $node is null $node evaluates to FALSE

This is so ridiculous, I could not believe my eyes. Nevertheless, it’s a bug. It does not occur with the latest version of PHP (5.6.15), although I could not find a specific fix that would be responsible for this in the PHP bugs database.

The trouble is, PHP 5.6.15 no longer supports Apache 2.2, which means I have to upgrade to Apache 2.4. This is probably a good idea anyway, but I hate this kind of domino effect.

Alternatively, I could ditch SimpleXML and switch to DOMDocument. Or write the whole thing I was writing (which is a test project anyway) in something more civilized like ASP.NET. Anyhow, fun stuff!

Update: PHP 5.4.45 does not have the bug. PHP guys seem to be doing a good job backporting bug fixes to older versions. Revolution averted 🙂

Update2 : Correction: in PHP 5.4.4 the node was not actually NULL, it was (incorrectly) evaluating to FALSE as if it were an empty tag. This, however, is still a bug. The fix in PHP 5.4.45 is also only partial. See my next post.

Leave a Reply

Your email address will not be published. Required fields are marked *