<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Defective Semantics &#187; php</title>
	<atom:link href="http://scarff.id.au/blog/tag/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://scarff.id.au</link>
	<description>Dean Scarff's perpetual struggle with technology, and other anecdotes</description>
	<lastBuildDate>Sat, 31 Jul 2010 02:44:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>PHP DOM XML default namespaces</title>
		<link>http://scarff.id.au/blog/2009/php-dom-xml-default-namespaces/</link>
		<comments>http://scarff.id.au/blog/2009/php-dom-xml-default-namespaces/#comments</comments>
		<pubDate>Mon, 21 Sep 2009 07:01:00 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Problems]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[dom]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[xml]]></category>

		<guid isPermaLink="false">http://scarff.id.au/?p=299</guid>
		<description><![CDATA[<p>Anyone that&#8217;s used PHP&#8217;s DOM XML knows that it&#8217;s a deprecated, buggy <acronym title="piece of shit">PoS</acronym>.  An undocumented memory leak in DOM XML resources and an equally undocumented workaround to manually free them are plenty of evidence for this.  Spare a thought for those of us who are on supported RHEL4 and stuck with PHP 4 and hence the DOM XML API.</p>
<p>My gripe today is with <code>create_element_ns</code>.  Terence Kearns has a pretty good summary of the issue in his comments.  Essentially, you cannot add a namespace to a node with the default prefix in a way that is recognised by the rest of DOM XML.  The problem is that supplying an empty <code>$prefix</code> parameter to <code>create_element_ns</code> is treated the same as omitting the <code>$prefix</code> parameter altogether, in which case DOM XML generates a random prefix.</p>
<p>The libxml2 convention is that passing a NULL prefix to xmlNewNs binds the default&#8230; <a href="http://scarff.id.au/blog/2009/php-dom-xml-default-namespaces/" class="read_more">more</a></p>]]></description>
			<content:encoded><![CDATA[<p>Anyone that&#8217;s used PHP&#8217;s DOM XML knows that it&#8217;s a deprecated, buggy <acronym title="piece of shit">PoS</acronym>.  An undocumented memory leak in DOM XML resources and an equally undocumented <a href="http://us2.php.net/manual/en/function.domxml-open-mem.php#37874">workaround</a> to manually free them are plenty of evidence for this.  Spare a thought for those of us who are on supported RHEL4 and stuck with PHP 4 and hence the DOM XML API.</p>
<p>My gripe today is with <code>create_element_ns</code>.  Terence Kearns has a pretty good summary of the issue in his <a href="http://au.php.net/manual/en/function.domnode-add-namespace.php#35855">comments</a>.  Essentially, you cannot add a namespace to a node with the default prefix in a way that is recognised by the rest of DOM XML.  The problem is that supplying an empty <code>$prefix</code> parameter to <code>create_element_ns</code> is treated the same as omitting the <code>$prefix</code> parameter altogether, in which case DOM XML generates a random prefix.</p>
<p>The libxml2 convention is that passing a NULL prefix to <a href="http://xmlsoft.org/html/libxml-tree.html#xmlNewNs">xmlNewNs</a> binds the default namespace, while passing an empty string is illegal.  Unfortunately, this convention might break a lot of PHP code that relies on DOM XML generating random namespace prefixes, because people are more likely to omit $prefix than to supply an empty string when they want the random-prefix behaviour.  However, I figure it&#8217;s better to break lazy code than to invert the libxml convention.</p>
<p>My <a href="/file/php-domxml-default-namespaces.patch">patch</a> changes the DOM XML behaviour so that an empty string prefix such as <code>$doc->create_element_ns('foo', 'http://example.net', '')</code> activates the old DOM XML random-prefix:</p>
<pre class="codeblock xml">
   &lt;a1337:foo xmlns:a1337="http://example.net" />
</pre>
<p>while omitting <code>$prefix</code> altogether as in <code>$doc->create_element_ns('foo', 'http://example.net')</code> binds the default namespace:</p>
<pre class="codeblock xml">
   &lt;foo xmlns="http://example.net" />
</pre>
]]></content:encoded>
			<wfw:commentRss>http://scarff.id.au/blog/2009/php-dom-xml-default-namespaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PHP array references</title>
		<link>http://scarff.id.au/blog/2008/php-array-references/</link>
		<comments>http://scarff.id.au/blog/2008/php-array-references/#comments</comments>
		<pubDate>Fri, 05 Sep 2008 05:54:25 +0000</pubDate>
		<dc:creator>Dean</dc:creator>
				<category><![CDATA[Problems]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[php]]></category>

		<guid isPermaLink="false">http://scarff.id.au/?p=117</guid>
		<description><![CDATA[<p>Hit this one at work, where we use RHEL4&#8242;s PHP 4.3.9.</p>
<p>The online documentation doesn&#8217;t mention it any more, but there&#8217;s a history of PHP not dealing well with array references.</p>
<p>PHP segfaults.  Unfortunately it&#8217;s quite hard to reproduce artificially; we don&#8217;t see the segfault until way after the reference was taken (presumably after the GC has done its rounds).  It&#8217;s 100% reproducible in our program, but I&#8217;m still working on a minimal test case.</p>
]]></description>
			<content:encoded><![CDATA[<p>Hit this one at work, where we use RHEL4&#8242;s PHP 4.3.9.</p>
<p>The <a href="http://www.php.net/references">online documentation</a> doesn&#8217;t mention it any more, but there&#8217;s a history of PHP <a href="http://bugs.php.net/bug.php?id=20993">not dealing well with array references</a>.</p>
<p>PHP segfaults.  Unfortunately it&#8217;s quite hard to reproduce artificially; we don&#8217;t see the segfault until way after the reference was taken (presumably after the GC has done its rounds).  It&#8217;s 100% reproducible in our program, but I&#8217;m still working on a minimal test case.</p>
]]></content:encoded>
			<wfw:commentRss>http://scarff.id.au/blog/2008/php-array-references/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
