Reputation: 99
I'm trying to make an xmlhttp request and print out the xml. I created a class with methods and am calling those methods from an object. However, when I attempt to print the output of the method, I get nothing. I'm guessing it's something minor, but I've been trying for awhile now and have made little progress. Thanks in advance for the help.
<?php
class twitter {
public $screen_name;
public $xml;
public $count;
public function getUserTimeline($screen_name, $count=5) {
$request= "https://api.twitter.com/1/statuses/user_timeline.xml?include_entities=true&include_rts=true&screen_name=$screen_name&count=$count";
return $this->makeRequest($request);
}
public function makeRequest($request){
return $xml = simplexml_load_file($request);
}
}
$test = new twitter;
$test->screen_name="mattcutts";
$test->getUserTimeline($screen_name=$test->screen_name, $count=5);
print_r($test->xml); //This does not print anything.
?>
Upvotes: 0
Views: 126
Reputation: 540
To create twitter object you must use constructor. So instead of $test = new twitter;
use $test = new twitter();
Upvotes: -2
Reputation: 4330
You try to access xml variable. But you didn't set it. You can change your method as following.
public function makeRequest($request){
$this->xml = simplexml_load_file($request);
}
Or you can print $xml as following way.
$xmp = $test->getUserTimeline($screen_name=$test->screen_name, $count=5);
print_r($xml);
Upvotes: 1
Reputation: 724452
You're creating and returning a local variable $xml
here in your makeRequest()
method:
return $xml = simplexml_load_file($request);
That should simply be $this->xml
:
$this->xml = simplexml_load_file($request);
Upvotes: 4