title: Problem with dom_import_simplexml on newly created SimpleXML nodes
body: <p>I'm working on a class extending <code>SimpleXMLElement</code>:</p>
  
  <pre><code>class MyXML extends SimpleXMLElement {
      public function cdata($text) {
          $node = dom_import_simplexml($this);
          $owner = $node-&gt;ownerDocument;
          $node-&gt;appendChild($owner-&gt;createCDATASection($text));
          return $this;
      }
  }
  </code></pre>
  
  <p>Since it's an <code>SimpleXMLElement</code>, I can dynamically create XML nodes inside it:</p>
  
  <pre><code>$xml = new MyXML('&lt;foo/&gt;');
  $xml-&gt;bar = 'Test';
  print $xml-&gt;asXML(); // &lt;foo&gt;&lt;bar&gt;Test&lt;/bar&gt;&lt;/foo&gt;
  </code></pre>
  
  <p>But when I try to run this:</p>
  
  <pre><code>$xml = new MyXML('&lt;foo/&gt;');
  $xml-&gt;bar-&gt;cdata('Test');
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>Warning: dom_import_simplexml(): Invalid Nodetype to import in [..]
  </code></pre>
  
  <p>However, if I force the <code>SimpleXMLElement</code> node to be created before running <code>cdata()</code>, it works again:</p>
  
  <pre><code>$xml = new MyXML('&lt;foo/&gt;');
  $xml-&gt;bar = '';
  $xml-&gt;bar-&gt;cdata('Test');
  print $xml-&gt;asXML(); // &lt;foo&gt;&lt;bar&gt;&lt;![CDATA[Test]]&gt;&lt;/bar&gt;&lt;/foo&gt;
  </code></pre>
  
  <p>I'm curious if what I found is a bug, and if there is any way to work around it without "priming" the node first.</p>