title: PHP - E_STRICT: Creating default object from empty value
body: <p>I see there are about a hundred different questions on here for <code>Creating default object from empty value</code>. None of them really seem to help with my issue.</p>
  
  <p>I am assigning a child object of the same class in a method. This triggers the <code>Creating default object from empty value</code> error.</p>
  
  <pre><code>class myClass {
  
  
      function __construct($rootName, $allowHTML = false, $endTag = true) {
          $this-&gt;rootElement = $rootName;
          $this-&gt;elements = array();
          $this-&gt;attributes = array();
          $this-&gt;value = "";
          $this-&gt;allowHTML = $allowHTML;
          $this-&gt;endTag = $endTag;
          $this-&gt;styles = array();
          $this-&gt;childID = 0;
      }
  
      // ... OTHER METHODS HERE (ALL PROPERTIES DECLARED)
  
      function assignElement(&amp;$theElement) {
          // Get the index.
          $index = count($this-&gt;elements);
  
          // Assign the element.
          $this-&gt;elements[$index] = $theElement;
  
          if (get_class($theElement) == get_class($this)) {
              $this-&gt;elements[$index]-&gt;childID = $index;
          }
  
          // Return the node.
          return $this-&gt;elements[$index];
      }
  }
  </code></pre>
  
  <p>The error occurs on <code>$this-&gt;elements[$index]-&gt;childID = $index;</code>. How do I handle this properly?</p>