Trying to use arrays inside a class

I am trying to use a class to display an RSS feed. For this example, I am using the BBC RSS feed. The code below is supposed to display first four RSS feed entries:

<?php
class Rss_feed
{
   public $title = array();
   public $description = array();
   
   public function __construct($feed_url,$n) {
    $rss = simplexml_load_file($feed_url);
    $i = 0;
    foreach ($rss->channel->item as $feedItem) {
        $i++;
        $this->title[i] = $feedItem->title;
        $this->description[i] = $feedItem->description;
        if ($i>=$n) break;
    }
   }
}

$BBC_feed = new RSS_feed("http://newsrss.bbc.co.uk/rss/newsonline_world_edition/front_page/rss.xml",4);

for ($i==0; $i<=4; $i++)
{ 
echo "<h2>" . $BBC_feed->title[$i] . "</h2>" . "<BR>\
";
echo $BBC_feed->description[$i] . "\
<BR><BR>";
}
?>

However, when I try to display arrays title and description by index, they come out empty in HTML. On the other hand, when parsing the RSS feed directly (via $rss = simplexml_load_file($feed_url); echo $rss->channel->item[0]->title; etc) it works fine. So, the problem is in the way I am handling arrays inside a class, I presume. Could you please point out what is wrong with my code? Thank you.

$this->title[i]
should be
$this->title[$i]

There are a few other little things you’ll need to change too. You should be testing with errors showing or logging. Try this at the top of your file (remove when you’re done).


error_reporting( E_ALL );
ini_set( 'display_errors', 1 );