title: PHP DomDocument appendChild() on a non object
body: <p>I have a PHP class that is used to generate some HTML in the following way:</p>
  
  <pre><code>public $rName;
  public $cName;
  public $rMonth;
  
  function __construct(){
      $this-&gt;report = new DOMDocument;
      $this-&gt;report-&gt;loadHTMLFile('template.php');
  }
  
  private function addComponent($tag, $content){
      $parent = $this-&gt;report-&gt;getElementById('content');
      $child = $this-&gt;report-&gt;createElement($tag, $content);
      $parent-&gt;appendChild($child);
  }
  
  function addSection($header){
      $this-&gt;addComponent('h2', $header);
  }
  
  function addSubHeader($subHeader){
      $this-&gt;addComponent('h3', $subHeader);
  }
  
  function addContent($content){
      $this-&gt;addComponent('p', $content);
  }
  </code></pre>
  
  <p>which is being called like this:</p>
  
  <pre><code>$report = new Report;
  
  $outputType = $_GET['outputType'];
  
  $report-&gt;rName = 'rName';
  $report-&gt;cName = $_GET['cName'];
  $report-&gt;rMonth = $_GET['rMonth'];
  
  $report-&gt;addSection('Section');
  $report-&gt;addSubHeader('SubHeader');
  $report-&gt;addContent('Content');
  </code></pre>
  
  <p>Using XAMPP on Windows, this code works absolutely fine. However on a centos environment I get the error:</p>
  
  <blockquote>
    <p>Call to a member function appendChild() on a non-object on line 16</p>
  </blockquote>
  
  <p>Line 16 is:</p>
  
  <pre><code>$parent-&gt;appendChild($child);
  </code></pre>
  
  <p>The template.php file appears to be loading, and there is a div with the id of "content", however a gettype() on $parent shows it as NULL.</p>
  
  <p>Pretty stumped at the moment. Any ideas? </p>