title: Trying to get property of a non object on rss feed script
body: <p>I have the following script</p>
  
  <pre><code>public function NewsRss() {
  $rss = new DOMDocument();
  libxml_use_internal_errors(true);
  $rss-&gt;load('http://www.autoexpress.co.uk/feeds/all');
  $feed = array();
  foreach ($rss-&gt;getElementsByTagName('item') as $node) {
    $htmlStr = $node-&gt;getElementsByTagName('description')-&gt;item(0)-&gt;nodeValue;
    $html = new DOMDocument();        
    $html-&gt;loadHTML($htmlStr);
    $desc = $html-&gt;getElementsByTagName('p')-&gt;item(0)-&gt;nodeValue;
    //var_dump($desc);
    $imgTag = $html-&gt;getElementsByTagName('img');
    $img = ($imgTag-&gt;length==0)?'noimg.png':$imgTag-&gt;item(0)-&gt;getAttribute('src');
    $item = array (
      'title' =&gt; $node-&gt;getElementsByTagName('title')-&gt;item(0)-&gt;nodeValue,
      'desc' =&gt; $desc,
      'link' =&gt; $node-&gt;getElementsByTagName('link')-&gt;item(0)-&gt;nodeValue,
      'date' =&gt; $node-&gt;getElementsByTagName('pubDate')-&gt;item(0)-&gt;nodeValue,
  'image' =&gt; $img,
    );
    array_push($feed, $item);
  }
  $limit = 3;
  for($x=0;$x&lt;$limit;$x++) {
    $title = str_replace(' &amp; ', ' &amp;amp; ', $feed[$x]['title']);
    $link = $feed[$x]['link'];
    $description = $feed[$x]['desc'];
    $date = date('l F d, Y', strtotime($feed[$x]['date']));
    echo '&lt;div class="news-row-index"&gt;';
    echo '&lt;div class="details-index"&gt;&lt;p&gt;&lt;h5&gt;&lt;a href="'.$link.'" target="_blank" title="'.$title.'"&gt;'.$title.'&lt;/a&gt;&lt;/h5&gt;';
    echo '&lt;small&gt;&lt;em&gt;Posted on '.$date.'&lt;/em&gt;&lt;/small&gt;&lt;/p&gt;';
    echo '&lt;div class="img"&gt;&lt;a href="'.$link.'" target="_blank" title="'.$title.'"&gt;&lt;img src="'.$feed[$x]['image'].'" height="79" width="89"&gt;&lt;/a&gt;&lt;/div&gt;';
    echo '&lt;p&gt;'.$description.'&lt;/p&gt;&lt;/div&gt;';
    echo '&lt;/div&gt;';
  }
  echo '&lt;a style="margin-left:10px;" class="view-all-but" target="_blank" href="http://www.autoexpress.co.uk/feeds/all"&gt;View all&lt;/a&gt;';
  </code></pre>
  
  <p>}</p>
  
  <p>The problem is that us showing me a notice like this
  <code>Notice: Trying to get property of non-object in  on line 10</code> which is
  <code>$desc = $html-&gt;getElementsByTagName('p')-&gt;item(0)-&gt;nodeValue;</code> but if I hide the errors everything works fine, just that i am trying to clean up my script of errors, and on this case don't know exactly where to start. I know that <code>-&gt;</code> should not be used many times.
  Please help me on this, it will be much appreciated. I am kind of a noob in OOP and rss.</p>