
{"id":1849,"date":"2016-01-02T01:59:38","date_gmt":"2016-01-02T06:59:38","guid":{"rendered":"http:\/\/www.ikriv.com\/blog\/?p=1849"},"modified":"2016-01-02T01:59:38","modified_gmt":"2016-01-02T06:59:38","slug":"php-bug-version-dependency-hell","status":"publish","type":"post","link":"https:\/\/ikriv.com\/blog\/?p=1849","title":{"rendered":"PHP bug + version dependency hell"},"content":{"rendered":"<p>I have discovered a bug in PHP 5.4.4: a simple XPATH does not work.<\/p>\n<p><code><\/p>\n<pre>$xml = simplexml_load_string(\"&lt;root&gt;&lt;a\/&gt;&lt;b&gt;text&lt;\/b&gt;&lt;\/root&gt;\");\n$node = $xml->xpath(\"\/root\/b\")[0]; \/\/ <strike>$node is null<\/strike> $node evaluates to FALSE<\/pre>\n<p><\/code><\/p>\n<p>This is so ridiculous, I could not believe my eyes. Nevertheless, it&#8217;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.<\/p>\n<p>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.<\/p>\n<p>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!<\/p>\n<p><b>Update<\/b>: 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 \ud83d\ude42<\/p>\n<p><b>Update2 <\/b>: 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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I have discovered a bug in PHP 5.4.4: a simple XPATH does not work. $xml = simplexml_load_string(&#8220;&lt;root&gt;&lt;a\/&gt;&lt;b&gt;text&lt;\/b&gt;&lt;\/root&gt;&#8221;); $node = $xml->xpath(&#8220;\/root\/b&#8221;)[0]; \/\/ $node is null $node evaluates to FALSE This is <a href=\"https:\/\/ikriv.com\/blog\/?p=1849\" class=\"more-link\">[&hellip;]<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"Layout":"","footnotes":""},"categories":[4,15],"tags":[],"class_list":["entry","author-ikriv","post-1849","post","type-post","status-publish","format-standard","category-hack","category-webdev"],"_links":{"self":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1849","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1849"}],"version-history":[{"count":0,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/1849\/revisions"}],"wp:attachment":[{"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1849"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1849"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ikriv.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1849"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}