PHP Variable Instantiated in Constructor resetting to null -


i'm writing small rss parser in php, i'm using simplexml, , i've come across problem. i've created class called articleformatter, here is

class articleformatter {      private $feeddata;      function __construct($feedurl) {         $feeddata = simplexml_load_file($feedurl);     }      function parse() {         echo " \n begin parsing \n";         $rawarticles = $feeddata->channel[0];         print_r($rawarticles);         echo "\n";         $currentarticle = $rawarticles->item[0];         print_r($currentarticle);         $articles = array();         echo "\n starting loop \n";         for($i = 0; !is_null($currentarticle); $i++) {             echo "ran";             array_push($articles, $currentarticle);             $currentarticle = $rawarticles->item[$i + 1];         }         return $articles;     }  } 

now here's thing, know simplexml_load_file returning legitimate simplexmlelement, because when put print statement inside of constructor, prints out kinds of xml elements, and, what's more, know $feeddata->item[0] legitimate simplexmlelement, because i've tried printing in constructor. yet, when parse() run is, gets printed out "begin parsing starting loop array ( )" (the code calls function prints out return value). suggesting me that, when parse function runs, $feeddata somehow equal null, , function returns nothing empty array. i'm sure i'm making stupid mistake somewhere, suggestions appreciated.

in php, if want call methods or use properties of class in, always have use $this:

function __construct($feedurl) {     $this->feeddata = simplexml_load_file($feedurl); }   function parse() {         echo " \n begin parsing \n";         $rawarticles = $this->feeddata->channel[0];         print_r($rawarticles);         ... } 

Comments